Update remote branch after rewriting history

Git, Branch · Apr 13, 2021

Forces an update of the remote branch after rewriting the history locally.

  • Use git push -f to force update the remote branch, overwriting it using the local branch's changes.
  • This operation is necessary anytime your local and remote repository diverge.
git push -f
git checkout patch-1
git pull
git rebase master
# Local `patch-1` branch has been rebased onto `master`, thus diverging
# from the remote `patch-1` branch

git push -f # Force update the remote `patch-1` branch

Written by Angelos Chalaris

I'm Angelos Chalaris, a JavaScript software engineer, based in Athens, Greece. The best snippets from my coding adventures are published here to help others learn to code.

If you want to keep in touch, follow me on GitHub.

More like this

  • Rename remote branch

    Renames a branch both locally and on the remote.

    Git, Branch · Apr 13, 2021

  • Create a new branch

    Creates and switches to a new branch, optionally setting up a remote tracking branch.

    Git, Branch · Apr 13, 2021

  • Undo a commit in Git

    Learn the simple way to undo a commit in Git without rewriting history.

    Git, Commit · May 27, 2023