Creating Remote Branches
git branch用得也不是很多,但有时候要用的时候往往会忘记,现将创建远程分支的过程列举如下:
一,确认我们所在的分支
elisonwu$ git branch
* master
二,假如我们要创建的分支v0
elisonwu$ git branch v0
三,将我们新创建的v0分支提交到远程,让项目组的其他成员都可看得到
git push 语法: git push [remote-repository-name] [branch-or-commit-name]:
elisonwu$ git push origin v0
Total 0 (delta 0), reused 0 (delta 0)
To file:///home/gitadmin/project1.git
* [new branch] v0 -> v0
Currently the master and v0 branches are identical, but they will diverge (the whole point of branches is to diverge)
as users make different commits to each branch.
四,configure new branch
当你做完这些还不够,对于本地的branch 的配置不完全
elisonwu$ git checkout v0
Switched to branch 'v0'
elisonwwu$ git pull
You asked me to pull without telling me which branch you
want to merge with, and 'branch.v0.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull ').
See git-pull(1) for details.
If you often merge with the same branch, you may want to
use something like the following in your configuration file:
[branch "v0"]
remote =
merge =
[remote ""]
url =
fetch =
See git-config(1) for details.
如果你喜欢练习打字的话, 你可以一直都指定repository (origin) and the branch (v0) ,当你需要pull, push, fetch时:
elisonwu$ git pull origin v0
From file:///home/gitadmin/project1
* branch v0 -> FETCH_HEAD
Already up-to-date.
但是有一天,你如果对于每次的输入厌烦了的话,你可以考虑配置下branch,以此来改变这一尴尬局面,
这里提供两种设置方式:
elisonwu$ git branch --set-upstream v0 origin/v0
Branch v0 set up to track remote branch v0 from origin.
而对于你的git版本早于1.7的版本也可以用
$ git config branch.v0.remote origin $ git config branch.v0.merge refs/heads/v0
从你决定开始要配置的那一刻开始,你将会感觉到操作是如此的轻松:
elisonwu$ git pull
Already up-to-date.
奉上所有,enjoy it!