How to git check out a remote branch named just like a directory?

We have a remote branch called deploy to create and test deployment scripts. Not surprisingly, deployment scripts end in a directory called deploy . Now that the deploy directory is in the master branch, when executing the initial clone, it is cumbersome to really check this branch.

 $ git clone bitbucket.org:/myplace/mything $ cd mything $ ls deploy extensions installExtensions src tests $ git branch -r | grep dep origin/deploy $ git checkout deploy $ git branch * master $ git checkout origin/deploy Note: checking out 'origin/deploy'. You are in 'detached HEAD' state. [SNIP] 

At this point, should I just create a local branch called deploy and set it to track the remote? Is there any syntax that I can give git, so it knows that I want to check the remote branch, and not the local path?

+6
source share
2 answers

You can simply create a new local branch pointing to the remote branch using any of these commands (the latter will check it immediately):

 git branch deploy origin/deploy git checkout -b deploy origin/deploy 

However, this will not lead to the configuration of the tracking functions that occur when Git automatically creates a branch for the remote branch. To do this, you need to do the following:

 git branch -u origin/deploy 

Alternatively, you can do this all in one command, which will be the same as Git:

 git checkout -b deploy --track origin/deploy 
+9
source

My workaround for this is

git checkout deploy --

0
source

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


All Articles