Force pushing to different Git remotes

July 27, 2021

My Git/GitHub workflow has continued to evolve and now makes extensive use of rebasing and squashing instead of merge commits. While this is easy for branches in projects I maintain, it’s more complicated for forks of my projects. In those cases, I need to checkout, rebase, squash, and force push a branch to a different remote with a different branch name.

Once you get your own copy of the fork’s branch locally and you’re ready to force push your rebased and/or squashed changes, here’s how you can push your changes from the terminal:

git push remoteName localBranch:remoteBranch --force

Before you push, you may need to add the fork as a new Git remote:

git remote add remoteName git:https://github.com/user/repo.git

Not familiar with force pushing, or squashing and rebasing? Consider exploring the GitHub rebase docs.