【问题标题】:Does the local GIT Branch and remote GITHUB branch need to be the same to push the code? [duplicate]本地 GIT 分支和远程 GITHUB 分支是否需要相同才能推送代码? [复制]
【发布时间】:2020-09-05 04:21:28
【问题描述】:

我创建了一个新的本地分支并尝试将代码推送到新的远程分支。当本地和远程分支名称不同时,代码不会被推送。但是当名称相同时,代码就会被推送。这种行为是正常的还是我错过了什么?提前致谢。

【问题讨论】:

    标签: git github


    【解决方案1】:

    对于一个基本的完整推送命令,就像

    git push <remote> <local_revision>:<remote_ref>
    

    &lt;local_revision&gt;:&lt;remote_ref&gt; 是 refspec。

    例如,推送提交abc123 的第二个父级以创建新的引用refs/sandbox/foo,

    git push origin abc123^2:refs/sandbox/foo 
    

    将本地master推送到远程(本例中为origin)master,

    git push origin refs/heads/master:refs/heads/master
    

    当master确实是一个分支时,如果没有命名冲突,我们可以省略refs/heads/部分,

    git push origin master:master
    

    当本地分支和目标分支都命名为master时,我们可以省略目标分支名称,

    git push origin master
    

    借助一些配置变量,我们可以进一步缩短命令。当当前分支为master,并且在git config中设置了branch.master.remote=origin和remote.origin.push=refs/heads/*:refs/heads/*,我们可以简单地运行git push。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-25
      • 2022-11-19
      • 2015-04-02
      • 2015-12-19
      • 2014-02-04
      • 2012-10-07
      • 2011-09-10
      相关资源
      最近更新 更多