Pro Git-- 跟踪分支

本地仓库的所有分支可以跟踪远程仓库的远程分支, 这样在当前本地分支上做pull, push时候,可以省略本地分支和远程分支名。

远程仓库名一般为remote(如果你clone远程仓库时默认设置)或者orgin. 可以使用 git remote add <远程仓库别名> URL 来指定。

 1. 设置 branch tracking, 远程分支foo, 远程仓库名 origin

  git branch -u upstream/foo

或者如果本地分支不是当前分支,可以:
git branch -u upstream/foo foo

    以下是两个命令的全写:

git branch --set-upstream-to=upstream/foo
git branch --set-upstream-to=upstream/foo foo


2. 查看追踪分支信息
 a) git branch -vv 跟踪的远程分支显示为蓝色
[krystal@localhost survey-nodejs]$ git branch -vv
* login-module 1ab69c5 fix last checkin
  master       1ab69c5 [origin/master] fix last checkin

  b)  使用 git rev-parse --abbrev -ref <分支名>@{upstream}

[krystal@localhost survey-nodejs]$ git branch -vv
* login-module 1ab69c5 fix last checkin
  master       1ab69c5 [origin/master] fix last checkin

 

  

原文地址:https://www.cnblogs.com/joshuajiang/p/4638357.html