A branch by any other name

Originally written on April 1, 2016

Normally when you're pushing to a remote repository, you want it to reflect the name you specified locally. In some fringe cases, though, you'll need a different name to explicitly state that this branch is a "scratch" branch that shouldn't be used.

To push to a remote branch that needs to be a different name than your local branch, separate your local and remote names with a colon:

git push origin local:remote

If you'd rather not run this command every time you push to the remote branch, you can add an upstream reference to the above command. Prefix your git push command with the -u flag like so:

git push -u origin local:remote

After using the -u flag when pushing to your remote branch, you will be able to run git push and git will automatically know to push to the remote git branch of a different name specified in your original push ☺️.