Skip to main content

Pushing to a differently named branch on your remote

Posted in Development and Git

When working with Git, it’s pretty normal to work on a branch locally and push it to an identically named branch on your remote (in GitHub/GitLab/Bitbucket/etc.).

git push origin my-great-feature

This command tells Git to push the work from your local feature branch to the remote repository, using the same branch name (my-great-feature) to either:

  • create the my-great-feature branch if it doesn’t already exist up there
  • add the work since your last push to the my-great-feature branch you already created

But sometimes you might want to push to a branch that’s not called the same thing as your local branch.

Admittedly, it’s not very often I have to do that, but here are a couple of recent examples:

  • I needed to demo some functionality for a client on a central staging URL that was linked to a staging branch
  • I wanted to test a redirect on a remote server

In both cases, I could create a staging branch locally, merge the work from the feature branch to it, then push, but that feels like extra steps when there’s a simpler way:

git push origin my-great-feature:staging

This tells git to push the work from your local my-great-feature branch to a remote branch named staging.

You might run into conflicts if you’ve used the staging branch for experimental things before, in which case just force your branch to overwrite what’s on your remove with the -force (or -f) flag:

git push -f origin my-great-feature:staging

Even better, if you’ve set up automatic deployments to your staging branch with something like Netlify, the work will appear on your staging site automatically!

Accessibility in your inbox

I send an accessibility-centric newsletter on the last day of every month, containing:

  • A roundup of the articles I’ve posted
  • A hot pick from my archives
  • Some interesting posts from around the web

I don’t collect any data on when, where or if people open the emails I send them. Your email will only be used to send you newsletters and will never be passed on. You can unsubscribe at any time.

More posts

Here are a couple more posts for you to enjoy. If that’s not enough, have a look at the full list.

  1. Avatars and alt text

    I really enjoyed Nicolas Steenhout’s recent article on Alt text for avatars or user photos. But there is a context where I would break his rule…

  2. Upgrading from iPhone 13 mini to 16 Pro

    I get a new phone every 3-ish years, give mine to my wife, and now she gives hers to our daughter. I got a 16 Pro this year! Here’s the skinny.