git新建一个分支--set-upstream

 

 一。使用场景: 本地新建一个分支后,必须要做远程分支关联。如果没有关联,git会在下面的操作中提示你显示的添加关联。关联目的是如果在本地分支下操作: git pull, git push ,不需要指定在命令行指定远程的分支.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值