Creating a local branch from a remote branch

I want to create a local and remote branch named test from the development branch by origin. However, although my current local branch is tracking the origin / development, when I check for a new branch, it originates / master. Therefore, I have to follow these steps to get the test branch on both the remote and the local.

git checkout -b test ( By default it picks origin/master though my current branch tracks origin/develop) git fetch origin git reset --hard origin/develop git push -u origin test 
+4
source share
1 answer

In accordance with the documentation

 git checkout -b test --track origin/develop 

gotta do the trick.


As additional goodies, if you want to create a local branch to track the remote branch of the same name, you can be lazy to omit the -b option

 git checkout --track origin/develop 

will create and verify a local branch named develop , which is equivalent

 git checkout -b develop --track origin/develop 

From document

As a convenience, --track without -b means creating a branch.

[...]

If the -b option is not specified, the name of the new branch will be removed from the remote tracking branch.

+9
source

Source: https://habr.com/ru/post/1487578/


All Articles