git - pull 和推的不同默认远程,同时允许手动指定一个

标签 git git-push git-pull git-remote

我有一个本地 Git 存储库,它有两个 Remote 。 originupstream 的分支。我在 master 上工作。我想实现这一目标:

  • git pull 等同于git pull upstream master
  • git push 等同于git push origin master
  • git pull origin masterorigin
  • pull
  • git push upstream master 推送到upstream

因此将 originupstream 同步的工作流程将简化为

git pull  # from upstream
git push  # to origin

我已经成功地使用一系列 git config 命令的以下结果配置了第一部分:

[branch "master"]
    remote = upstream
    merge = refs/heads/master
    pushRemote = origin

但是,git push 给我这个错误:

fatal: You are pushing to remote 'origin', which is not the upstream of
your current branch 'master', without telling me what to push
to update which remote branch.

有什么想法吗?

最佳答案

这实际上应该在 >= 2.0 的 Git 版本中“开箱即用”,按照您配置的方式。

显然,根据评论,您还必须显式配置 push.defaultsimple ,即使这是未配置的默认值 push.default . (将 push.default 设置为 current 也可以,但会删除 simple 为某些推送添加的安全检查。)

请注意,您可以使用 git branch --set-upstream-to 设置任何分支的上游:

git branch --set-upstream-to=upstream/master master

但它确实需要 git config命令(或直接编辑配置文件——我喜欢自己经常使用 git config --edit,尤其是修复拼写错误)来设置 pushRemote以及,您需要实现您想要实现的目标。

关于git - pull 和推的不同默认远程,同时允许手动指定一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50886573/

相关文章:

git - 如何压缩分支中的所有 merge ?

git - 使 git pull 显示更新文件的当前目录的相对路径

regex - 使用带有否定前瞻的 grep 不返回任何匹配项

git - git push origin HEAD 是什么意思?

git - Visual Studio 2013 git 客户端 - 强制推送

git push heroku master 说 "Everything up-to-date",但应用程序不是最新的

git - 为什么 Git 有工作区、暂存区和本地存储库?

Git 从不同的仓库中 pull 一个分支

git - 如何修复已删除的 git 提交分支或引用?

GIT pull error - 远程对象已损坏