How Do I Push a New Local Branch to a Remote Git Repository and Track It Too?

Better Stack Team
Updated on June 24, 2024

To push a new local branch to a remote Git repository and track it, you can use the git push command with the --set-upstream or -u option. Here's how you can do it:

 
git push -u origin <local-branch-name>

Replace <local-branch-name> with the name of your new local branch.

Explanation:

  • git push: This command is used to push changes from your local repository to a remote repository.
  • u or -set-upstream: This option tells Git to set up tracking so that your local branch will track the remote branch with the same name on the remote repository (origin).
  • origin: This is the default name Git gives to the remote repository. If your remote repository has a different name, replace origin with the appropriate remote name.
  • <local-branch-name>: This is the name of the new local branch you want to push to the remote repository.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github