确保本地分支提交/推送到右侧远程分支

时间:2013-11-17 23:41:28

标签: git github

当我运行“git remote show guarddog”时,我希望看到类似这样的内容:

  Local ref configured for 'git push':
    guarddoglocal pushes to master

然而,这实际上就是我所看到的:

git remote show guarddog
Username for 'github.com': 
Password for 'github.com': 
* remote guarddog
  Fetch URL: https://github.com/guarddog/guarddog.git
  Push  URL: https://github.com/guarddog/guarddog.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    guarddoglocal merges with remote master

显然,没有为git push配置guarddoglocal到guarddog / master。

这是我到目前为止所做的:

git remote -v
origin  https://github.com/usera/usera.git (fetch)
origin  https://github.com/usera/usera.git (push)

git remote add guarddog https://github.com/guarddog/guarddog.git
git remote -v
guarddog    https://github.com/guarddog/guarddog.git (fetch)
guarddog    https://github.com/guarddog/guarddog.git (push)
origin          https://github.com/usera/usera.git (fetch)
origin          https://github.com/usera/usera.git (push)

git status
# On branch useralocal
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   app/assets/javascripts/application.js.erb

git push guarddog useralocal:master

git checkout -b guarddoglocal guarddog/master

git branch
* guarddoglocal
  useralocal

git status
# On branch guarddoglocal
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   app/assets/javascripts/application.js.erb

git remote show guarddog
Username for 'github.com': 
Password for 'github.com': 
* remote guarddog
  Fetch URL: https://github.com/guarddog/guarddog.git
  Push  URL: https://github.com/guarddog/guarddog.git
  HEAD branch: master
  Remote branch:
    master tracked
      Local branch configured for 'git pull':
        guarddoglocal merges with remote master

正如您所看到的,拉动看起来合理,但默认推动没有。当我推动分支guarddoglocal时,我需要确保它推送到guarddog远程存储库。

尝试这样的事情不会改变任何事情:

git push -u guarddoglocal guarddog:master

1 个答案:

答案 0 :(得分:0)

我认为您错误地使用了-u选项

git push -u guarddog      guarddoglocal:master
            ^^^^^^^^      ^^^^^^^^^^^^^ ^^^^^^
            remote name   local branch  remote branch

guarddoglocal分支中,将其配置为跟踪master遥控器上的guarddog分支。