git新建一个分支--set-upstream
I create a new branch in Git:
git branch my_branch
Push it:
git push origin my_branch
Now say someone made some changes on the server and I want to pull from origin/my_branch. I do:
git pull
But I get:
You asked me to pull without telling me which branch you
want to merge with, and 'branch.my_branch.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 <repository> <refspec>').
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 "my_branch"]
remote = <nickname>
merge = <remote-ref>
[remote "<nickname>"]
url = <url>
fetch = <refspec>
See git-config(1) for details.
I learned that I can make it work with:
git branch --set-upstream my_branch origin/my_branch
注意,推送到远程分支后,默认也不是跟踪snsconnct:mater分支,你只要没有显示指定,git pull的时候,就会提示你。
二。替代:
该语法等价与在第一次提交分支时,使用git push -u origin my_branch:
一种更简单的方式用来取代不好忘记的 git branch --set-upstream 是git push -u origin my_branch
在你第一次提交你的分支的时候使用。它会像git branch --set-upstream一样在本地分支与远程分去建立联系。
通常我们在新建分支的时候,一定要显式建立这种联系。
三。类似
this be equivalent to what is automatically done when you initially clone a repository
附:
下面部分就是git clone之后,添加到文件里的内容。感觉git clone主要是cline仓库。用来初始化。所以,它不能取代--set-upstream.
[core]
repositoryformatversion = 0
filemode = true
logallrefupdates = true
autocrlf = false
bare = false
[remote "origin"]
url = ssh://root@hostname/path
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "sns"]
remote = origin
merge = refs/heads/sns
或者
# git remote add origin ssh://...
now configure master to know to track
# git config branch.master.remote origin
# git config branch.master.merge refs/heads/master
and push
# git push origin master
四。命令的最终修改都是针对config文件。
使用--set-upstream去跟踪远程分支。
config在命令执行之前:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = root@****************
[branch "master"]
remote = origin
merge = refs/heads/master
[remote "snsconnect"]
url = root@app220:/*******************
fetch = +refs/heads/*:refs/remotes/snsconnect/*
执行之后:
[branch "sns"]
remote = snsconnect
merge = refs/heads/sns