How do I push a new local branch to a remote Git repository and track it too? -Git push branch


I want to be able to do the following:

Create a local branch based on some other (remote or local) branch (via git branch or git checkout -b)
Push the local branch to the remote repository (publish), but make it trackable so git pull and git push will work immediately.
How do I do that?
I know about --set-upstream in Git 1.7, but that is a post-creation action. I want to find a way to make a similar change when pushing the branch to the remote repository.



You can directly use the below command to push all the branches to the remote.

git push --all -u


You can use the git checkout command to checkout for a new branch.

git checkout -b <branch-name>

Then edit the files, add them, and commit using the upstream option.

git push -u origin <branch-name>


If you want to unleash your potential in this competitive field, please visit the DevOps course page for more information, where you can find the DevOps tutorials and DevOps frequently asked interview questions and answers as well.


This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.