git - Different default remote for pull and push, while allowing manually specifying one
问题描述
I have a local Git repository that has two remotes. origin
is a fork of upstream
. I work on master
. I would like to achieve this:
git pull
is equivalent togit pull upstream master
git push
is equivalent togit push origin master
git pull origin master
pulls fromorigin
git push upstream master
pushes toupstream
So the workflow to sync origin
with upstream
would be simplified to
git pull # from upstream
git push # to origin
I've managed to configure the first part with the following result from a series of git config
commands:
[branch "master"]
remote = upstream
merge = refs/heads/master
pushRemote = origin
However, git push
gives me this error:
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.
Any ideas?
解决方案
这实际上应该在 Git 版本 >= 2.0 中“开箱即用”,即您配置事物的方式。
显然,根据评论,您还必须显式配置push.default
为simple
,即使这是未配置的默认值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
你想要实现的目标。
推荐阅读
- hazelcast-jet - 如何对异步接收数据的 hazelcast jet 源进行编程
- ant - 使用 ant 从共享位置获取/下载 jar
- c# - System.IO.FileLoadException:'无法加载文件或程序集'EntityFramework或其依赖项之一。访问被拒绝。
- python - 无法在端口 8000 上的谷歌云访问我的 django 应用程序
- php - 尝试显示 OPCache 的状态时出错。Laravel 和 appstract/laravel-opcache
- python - 查找最大空闲时间块
- javascript - Liferay 7 上的 Portlet 部署问题
- c - Binary Bomb Phase 5 - 寻找两个整数作为输入
- php - 如何使用 api 在 Dynamics crm 中设置leadsource?
- html - 如何将此行与 flexbox 对齐?