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. Images as the first thing in a button or link

    If the text of an interactive element like a button or link is preceded with an accessible image, we’ve probably got an accessibility problem.

  2. Alt text for CSS generated content

    There’s an interesting feature in Safari 17.4 that allows content added with CSS to have ‘alt’ text. I’m not sure how I feel about this.