Created
October 10, 2015 02:22
-
-
Save tuchangwei/03273c653515771fc782 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 跟踪远程分支 | |
| 从远程分支 checkout 出来的本地分支,称为 跟踪分支 (tracking branch)。跟踪分支是一种和某个远程分支有直接联系的本地分支。在跟踪分支里输入 git push,Git 会自行推断应该向哪个服务器的哪个分支推送数据。同样,在这些分支里运行 git pull 会获取所有远程索引,并把它们的数据都合并到本地分支中来。 | |
| 在克隆仓库时,Git 通常会自动创建一个名为 master 的分支来跟踪 origin/master。这正是 git push 和 git pull 一开始就能正常工作的原因。当然,你可以随心所欲地设定为其它跟踪分支,比如 origin 上除了 master 之外的其它分支。刚才我们已经看到了这样的一个例子:git checkout -b [分支名] [远程名]/[分支名]。如果你有 1.6.2 以上版本的 Git,还可以用 --track 选项简化: | |
| $ git checkout --track origin/serverfix | |
| Branch serverfix set up to track remote branch serverfix from origin. | |
| Switched to a new branch 'serverfix' | |
| 要为本地分支设定不同于远程分支的名字,只需在第一个版本的命令里换个名字: | |
| $ git checkout -b sf origin/serverfix | |
| Branch sf set up to track remote branch serverfix from origin. | |
| Switched to a new branch 'sf' | |
| 现在你的本地分支 sf 会自动将推送和抓取数据的位置定位到 origin/serverfix 了。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment