git 把远程分支拿到本地,并建立关联关系track

git 专栏收录该内容
4 篇文章 0 订阅

http://www.open-open.com/lib/view/open1328069889514.html

从远程分支 checkout 出来的本地分支,称为_跟踪分支(tracking branch)_。跟踪分支是一种和远程分支有直接联系的本地分支。在跟踪分支里输入git push,Git 会自行推断应该向哪个服务器的哪个分支推送数据。反过来,在这些分支里运行git pull 会获取所有远程索引,并把它们的数据都合并到本地分支中来。

在克隆仓库时,Git 通常会自动创建一个名为 master 的分支来跟踪 origin/master。这正是git push 和 git pull 一开始就能正常工作的原因。当然,你可以随心所欲地设定为其它跟踪分支,比如origin 上除了 master 之外的其它分支。刚才我们已经看到了这样的一个例子:git checkout -b [分支名] [远程名]/[分支名]

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (master)
$ git checkout --track origin/br-2.1.2.1
Branch br-2.1.2.1 set up to track remote branch br-2.1.2.1 from origin.
Switched to a new branch 'br-2.1.2.1'

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (br-2.1.2.1)
$ git status
# On branch br-2.1.2.1
nothing to commit, working directory clean

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (br-2.1.2.1)
$ git br
* br-2.1.2.1
  br-2.1.2.2
  master

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (br-2.1.2.1)

删掉刚才track的分支

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (master)
$ git br
  br-2.1.2.1
  br-2.1.2.2
* master

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (master)
$ git status
# On branch master
nothing to commit, working directory clean

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (master)
$ git branch -d br-2.1.2.1
warning: deleting branch 'br-2.1.2.1' that has been merged to
         'refs/remotes/origin/br-2.1.2.1', but not yet merged to HEAD.
Deleted branch br-2.1.2.1 (was cec094b).

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (master)
$ git br -v
  br-2.1.2.2 1dfeab3 [behind 9] 升级META客户端2.1.4.4
* master     89700a3 optimize upload file

使用checkout命令,创建新的分支 br-2.1.2.1,跟踪远程的origin/br-2.1.2.1

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (master)
$ git checkout -b br-2.1.1.1  origin/br-2.1.2.1
Branch br-2.1.1.1 set up to track remote branch br-2.1.2.1 from origin.
Switched to a new branch 'br-2.1.1.1'

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (br-2.1.1.1)
$ git status
# On branch br-2.1.1.1
nothing to commit, working directory clean

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (br-2.1.1.1)

$ git branch -a
* br-2.1.1.1
  br-2.1.2.2
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/br-2.1.2.1
  remotes/origin/br-2.1.2.2
  remotes/origin/br-2.1.3
  remotes/origin/master




  • 1
    点赞
  • 0
    评论
  • 3
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值