简体   繁体   中英

ensure local branch commits/pushes to right remote branch

When I run "git remote show guarddog", I am expecting to see something like this:

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

However, this is actually what I do see:

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

Clearly, guarddoglocal is not configured for git push to guarddog/master.

This is what I done so far:

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

As you can see, the pull looks reasonable, but the default push does not. When I push on branch guarddoglocal, I need to ensure it pushes to the guarddog remote repository.

Trying something like this doesn't change anything:

git push -u guarddoglocal guarddog:master

I think you are using the -u option wrongly

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

while in the guarddoglocal branch will configure it to track the master branch on the guarddog remote.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM