[git] git拉取远程指定分支到本地

git拉取远程指定分支到本地

我们经常会遇到,同事把一个分支(如feature-01)提交到了远程仓库,我们本地没有该分支,需要把该分支拉取到本地,查阅并修改,情况下如:

$ git branch -a
* dev
  master
  remotes/origin/dev
  remotes/origin/feature-01
  remotes/origin/master

要想把feature-01拉取到本地,使用下面的语法

$  git checkout -b feature-01 origin/feature-01
Branch 'feature-01' set up to track remote branch 'feature-01' from 'origin'.
Switched to a new branch 'feature-01'

若成功,将会在本地创建新分支 feature-01,并自动切到feature-01分支上。

语法

从远程仓库拉取一条本地不存在的分支时:

git checkout -b 本地分支名 origin/远程分支名

这个将会自动创建一个新的本地分支,并与指定的远程分支关联起来。

参考文章

猜你喜欢

转载自blog.csdn.net/weixin_36210698/article/details/88976398