简体   繁体   中英

creating local branch from remote develop branch

I want to create a local and a remote branch named test from the develop branch on origin. However, even though my current local branch is tracking origin/develop when I checkout the new branch it takes origin/master. Therefore, I have to follow the steps below to get a test branch on both remote and 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 

According to the documentation

git checkout -b test --track origin/develop

should do the trick.


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

git checkout --track origin/develop

will create and checkout a local branch named develop , thus being equivalent to

git checkout -b develop --track origin/develop

From the doc

As a convenience, --track without -b implies branch creation.

[...]

If no -b option is given, the name of the new branch will be derived from the remote-tracking branch.

Starting with Git 2.23 , you can also use:

git switch -t origin/<branch>

It creates and checkouts to a new local branch named <branch> tracking the remote origin/<branch> .

More details on the documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM