How to force push a single branch?

git push origin +branch_name

To force push a single branch use git push origin +branch_name, with the plus sign (+) before the branch name.

If you want to force push every branch instead, use git push --force.

Layer 1
Terminal Example
git status
On branch new-branch
Your branch and 'origin/new-branch' have diverged,
and have 1 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

nothing to commit, working tree clean

git push origin new-branch
To github.com:githint/playground-remote.git
 ! [rejected]        new-branch -> new-branch (non-fast-forward)
error: failed to push some refs to 'git@github.com:githint/playground-remote.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

git push origin +new-branch
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 239 bytes | 239.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:githint/playground-remote.git
 + d117d3e...36a8068 new-branch -> new-branch (forced update)

See git push to learn more about it.

Last modified on November 30, 2021.

You might also like