Git

How to push to a Different git Branch?

April 7, 2023

By default, when you push to a remote repository, Git pushes the current branch to the remote repository. However, there might be times when you want to push to a branch that is different from the current branch.

The syntax for pushing to a different branch is as follows:

git push <remote> <local_branch>:<remote_branch>

Let’s say you have a branch called main and you want to push your changes to a branch called staging. You can do so by running the following command:

git push origin main:staging

This will either create a new branch called staging or push your changes to an existing branch called staging.

© All rights reserved — cs.fyi