clone 某个分支:
git clone -b dev5 https://git.coding.net/aiyongbao/tradepc.git
clone 所有分支:
git clone https://git.coding.net/aiyongbao/tradepc.git
查看远程分支
git branch –r
创建本地分支18860127247 ,并自动关联远程分支 remotes/origin/18860127247
git checkout 18860127247
git clone默认会把远程仓库整个给clone下来;
但只会在本地默认创建一个master分支
如果远程还有其他的分支,此时用git branch -a查看所有分支:
$ git branch -a
* master
remotes/origin/13003829928
remotes/origin/13067413633
remotes/origin/13072807290
remotes/origin/13080927420
remotes/origin/13115923782
remotes/origin/13144317201
remotes/origin/13205029538
remotes/origin/13227096136
remotes/origin/13308329664
remotes/origin/13330265124
remotes/origin/13635286132
remotes/origin/15009295272
remotes/origin/15009295579
remotes/origin/15080002570
remotes/origin/15627361826
remotes/origin/15809238075
remotes/origin/15912074232
remotes/origin/15980181313
remotes/origin/15997295667
remotes/origin/15997504012
remotes/origin/17671742338
remotes/origin/17683258868
remotes/origin/17795835296
remotes/origin/18150647681
remotes/origin/18235352422
remotes/origin/18606027794
remotes/origin/18672963616
remotes/origin/18860127247
remotes/origin/18860127248
remotes/origin/HEAD -> origin/master
remotes/origin/linjiawei
remotes/origin/master
能看到远程的所有的分支,如remotes/origin/python_mail.skin
可以使用checkout命令来把远程分支取到本地,并自动建立tracking
- $ git checkout -b python_mail.skin origin/python_mail.skin
- Branch python_mail.skin set up to track remote branch python_mail.skin from origin
- Switched to a new branch 'python_mail.skin'
或者使用-t参数,它默认会在本地建立一个和远程分支名字一样的分支
- $ git checkout -t origin/python_mail.skin
windows下发现直接 git checkout 18860127247就可以自动创建本地分支,并关联, 如下:
$ git checkout 18860127247
Branch 18860127247 set up to track remote branch 18860127247 from origin.
Switched to a new branch '18860127247'
可用git help checkout 查看为啥
To prepare for working on <branch>, switch to it by updating the index and the files in the working tree, and by pointing HEAD at the branch. Local modifications to the files in the working tree are kept, so that they can be committed to the <branch>.
If <branch> is not found but there does exist a tracking branch in exactly one remote (call it <remote>) with a matching name, treat as equivalent to
$ git checkout -b <branch> --track <remote>/<branch>
You could omit <branch>, in which case the command degenerates to "check out the current branch", which is a glorified no-op with a rather expensive side-effects to show only the tracking information, if exists, for the current branch.
因为本地没有这个branch,并且远程正好有一个branch匹配了这个名字(输入branch名字可用用tab自动补全),这样相当于输入了 git checkout -b <branch> --track <remote>/<branch>