Git 分支跟踪详解(remote branch tracking)

6月 15, 2017 |

当我们执行如下动作时
本文由javacoder.cn 整理,转载请注明出处
1)git clone https://github.com/javacodercn/test_git.git
2)cd test_git
3)git branch -vv

* master 4889573 [origin/master] test git pull --rebase

表明本地的master分支自动设置为跟踪远程的"origin/master"分支
4)查看test_git/.git/config文件,有如下节

[branch "master"]
remote = origin
merge = refs/heads/master

5)git branch --no-track test1234
6)git branch -vv

* master 4889573 [origin/master] test git pull --rebase
test1234 4889573 test git pull --rebase

7)查看test_git/.git/config文件 没有添加新的内容

8)git branch -u origin/master test1234

9)git branch -vv

* master 4889573 [origin/master] test git pull --rebase
test1234 4889573 [origin/master] test git pull --rebase

10)查看test_git/.git/config文件,新的内容
[branch "test1234"]

remote = origin
merge = refs/heads/master

11)执行git config --local --list

core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
remote.origin.url=https://github.com/javacodercn/test_git.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.test1234.remote=origin
branch.test1234.merge=refs/heads/master

12)取消分支test1234跟踪
$ git branch --unset-upstream test12345
总结:某个本地分支是否跟踪某个远程的branch,就看.git/config文件中是否有对应的[branch "branchName"]这样的节配置

Posted in: Git

Comments are closed.