git 抓取远程分支到本地分支(本地不存在这个分支)

问题/需求:

本地仓库在工作电脑上,同时最新的更改已经推送到远程仓库,春节放假时有需求需要在家的电脑上建立仓库,同时建立了一个新分支"new",同时也推送到远程仓库中;

后来想把远程分支“new”抓取到工作电脑的本地仓库;

先查看本地分支

$ git branch
  front
* master

查看所有分支

$ git branch -a
  front
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/front
  remotes/origin/master

 不对呀,我远程仓库是由new分支的呀,为什么在这台电脑上查不到,难道branch 指令查询的数据不是实时数据仅仅是本地的数据,那只能抓取远程的所有分支到本地仓库了

$ git fetch --all
Fetching origin
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 9 (delta 7), reused 0 (delta 0)
Unpacking objects: 100% (9/9), done.
From https://gitee.com/xxxxxx/xxxx
 * [new branch]      new        -> origin/new

再查看分支

$ git branch -a
  front
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/front
  remotes/origin/master
  remotes/origin/new

好了显示远程仓库有new分支了, 现在需要将远程仓库拉取到本地了

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

然后再查看本地分支

$ git branch
  front
  master
* new

好了, 完成了

猜你喜欢

转载自www.cnblogs.com/jlicon/p/12297425.html