两个本地分支跟踪两个遥控器,如何才能自动推送一个?

时间:2013-08-19 09:21:51

标签: git version-control github

我跑了

$ git remote show origin
* remote origin
  Fetch URL: XXX/client.git
  Push  URL: XXX/client.git
  HEAD branch: (unknown)
  Remote branches:
    cancun                    tracked
    cancun_elad               tracked
    dragon                    tracked
    piano                     tracked
  Local branches configured for 'git pull':
    cancun_elad merges with remote cancun_elad
    piano       merges with remote piano
  Local refs configured for 'git push':
    cancun_elad pushes to cancun_elad (up to date)
    piano       pushes to piano       (local out of date)

然后我跑了

$ git push
Counting objects: 710, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (146/146), done.
Writing objects: 100% (426/426), 5.57 MiB | 1.05 MiB/s, done.
Total 426 (delta 353), reused 324 (delta 266)
To XXXX/client.git
   65c11e9..72b8931  cancun_elad -> cancun_elad
 ! [rejected]        piano -> piano (non-fast-forward)
error: failed to push some refs to ' XXX/client.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. If you did not intend to push that branch, you may want to
hint: specify branches to push or set the 'push.default' configuration
hint: variable to 'current' or 'upstream' to push only the current branch.

这是否意味着我推动了 本地pianocancun_elad?如果是这样,我该如何恢复piano推送?

如何配置git push只推送其中一个本地分支(cancun_elad)? push.default在哪里?

1 个答案:

答案 0 :(得分:0)

首先,除非您使用git push--force)选项重新运行最后一个-f,否则您应该没问题。虽然它尝试更新piano,但实际上并没有这样做,因为它是非快进更新。

通常,设置push.default的最佳位置在~/.gitconfig。在这种情况下,我认为您正在寻找push.default设置为upstream。如果您有兴趣,git-config手册页会提供有关其他值的更多信息。只需搜索push.default

您只需修改~/.gitconfig并添加:

即可
[push]
    default = upstream

或者,运行:

git config --global push.default upstream

任何一个人都可以做到这一点。

注意:upstream是文字upstream,而不是您要跟踪的分支的名称。

:: git config --global push.default upstream
:: git config -l | grep push.default
push.default=upstream