How to do a forced-push to another branch in Git

The + needs to come at the beginning of the argument representing the couple.

git push origin +localBranchName:remoteBranchName

That’s hard to remember sometimes, so there’s also the --force flag.

git push origin --force localBranchName:remoteBranchName

But be aware if you push multiple branches with that flag, then they will all be force pushed.

git push origin --force localBranchName:remoteBranchName anotherLocalBranch

In that case, you may not have wanted to force push anotherLocalBranch, so you should instead use the + to specify which ones you want forced.

git push origin +localBranchNameForced:remoteBranchName localBranchNotForced:remoteBranchNotForced +anotherLocalBranchForcePushedToUpstreamTracking

Do read Torek’s answer for a better explanation, and check out some of his other answers for world-class knowledge on git.

Leave a Comment