Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+5 votes
2 views
in DevOps and Agile by (19.4k points)
edited by

I want to be able to do the following:

  1. Create a local branch based on some other (remote or local) branch (via git branch or git checkout -b)
  2. 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.

 

1 Answer

+5 votes
by (27.5k points)
edited by

In order to create a new branch by branching off from an existing branch

git checkout -b <new-branch>

Then push this new branch to repository using

git push -u origin <new-branch>

What we did here? We have created and pushed all local commits to a newly created remote branch origin/<new_branch>

For better understanding about these git commands go through the following crash course on git that will help you to understand git well.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...