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>
?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With