Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force push current branch

I often rebase feature branches and then want to force push them to the server.

git push --force origin feature-mongodb-support 

Is there any shortcut for git push --force origin <current branch>?

like image 533
iblue Avatar asked Jul 12 '12 14:07

iblue


People also ask

How do I force a branch to push another branch?

In order to push a Git branch to remote, you need to execute the “git push” command and specify the remote as well as the branch name to be pushed. If you are not already on the branch that you want to push, you can execute the “git checkout” command to switch to your branch.

Can I force push on feature branch?

Actually, force pushing to a feature branch on which only you work is not bad practice at all. --force-with-lease is safer, not safe - it's still not generally a good thing to do on a shared branch.

What does force push do in git?

The --force option for git push allows you to override this rule: the commit history on the remote will be forcefully overwritten with your own local history. This is a rather dangerous process, because it's very easy to overwrite (and thereby lose) commits from your colleagues.


1 Answers

You can use aliases to shorten the command. Use it like this:

git config --global alias.fpush "push --force origin" 

Now to push your branch just type:

git fpush feature-mongodb-support 

Or you can even hardcode the branch name into the command:

git alias fpush "push --force origin feature-mongodb-support" 

and use only git fpush to push your precious work into the upstream.

However, non-fast-forward updates are dangerous since you will basically overwrite all the history on server that occurred between the last merge/rebase into your local branch and the forced push. If you need to do them often there is definitely something wrong in your workflow.

like image 59
Sergey K. Avatar answered Oct 14 '22 17:10

Sergey K.