如何使 git 配置尊重分支远程推送设置
how to make git config respect the branch remote push setting
我正在使用标准命名的分叉回购(我的分叉是 "origin",上游是 "upstream")。
我想建立两个本地分支,一个叫"master"跟踪upstream/master,另一个叫"my-forked-master"跟踪origin/master。
我希望 git 记住要推送到哪里,这样当我在 my-forked-master 分支上时,我只需要输入 "git push" 就可以得到 git推送到 origin/master.
我的 .git/config 文件中有这个:
[branch "my-forked-master"]
remote = origin
merge = refs/heads/master
push = refs/heads/master
[branch "master"]
remote = upstream
merge = refs/heads/master
但是当我在 my-forked-master 分支中键入 "git push" 时,git 在 origin/my-forked-master 上创建了一个新的远程分支。我已经尝试将 push.default 设置为 "current" 和 "simple" - 都不起作用。不管怎样,因为我明确设置了我的分支的远程和推送设置,所以我认为这样的默认值是无关紧要的。 (尽管它们似乎并不无关紧要——"simple" 触发有关分支名称不匹配的错误)。
如何让 git 服从 .git/config 中的内容并简单地推送到 origin/master,即使它与我的本地分支名称不匹配?
I've tried setting push.default to "current" and "simple" -- neither works.
正确的值为upstream
。 (simple
是 upstream
加上确保名称匹配以防止意外的检查——这在此处不起作用。)参见 the manual:
upstream
- push the current branch back to the branch whose changes are usually integrated into the current branch (which is called @{upstream}
). This mode only makes sense if you are pushing to the same repository you would normally pull from (i.e. central workflow).
Anyway, since I explicitly set my branch's remote and push settings, I thought such defaults would be irrelevant.
不确定 branch.<name>.push
是否存在。 branch.<name>.remote
和 branch.<name>.merge
是分支的上游,不过,这就是 push.default
设置的重点。
我正在使用标准命名的分叉回购(我的分叉是 "origin",上游是 "upstream")。
我想建立两个本地分支,一个叫"master"跟踪upstream/master,另一个叫"my-forked-master"跟踪origin/master。
我希望 git 记住要推送到哪里,这样当我在 my-forked-master 分支上时,我只需要输入 "git push" 就可以得到 git推送到 origin/master.
我的 .git/config 文件中有这个:
[branch "my-forked-master"]
remote = origin
merge = refs/heads/master
push = refs/heads/master
[branch "master"]
remote = upstream
merge = refs/heads/master
但是当我在 my-forked-master 分支中键入 "git push" 时,git 在 origin/my-forked-master 上创建了一个新的远程分支。我已经尝试将 push.default 设置为 "current" 和 "simple" - 都不起作用。不管怎样,因为我明确设置了我的分支的远程和推送设置,所以我认为这样的默认值是无关紧要的。 (尽管它们似乎并不无关紧要——"simple" 触发有关分支名称不匹配的错误)。
如何让 git 服从 .git/config 中的内容并简单地推送到 origin/master,即使它与我的本地分支名称不匹配?
I've tried setting push.default to "current" and "simple" -- neither works.
正确的值为upstream
。 (simple
是 upstream
加上确保名称匹配以防止意外的检查——这在此处不起作用。)参见 the manual:
upstream
- push the current branch back to the branch whose changes are usually integrated into the current branch (which is called@{upstream}
). This mode only makes sense if you are pushing to the same repository you would normally pull from (i.e. central workflow).
Anyway, since I explicitly set my branch's remote and push settings, I thought such defaults would be irrelevant.
不确定 branch.<name>.push
是否存在。 branch.<name>.remote
和 branch.<name>.merge
是分支的上游,不过,这就是 push.default
设置的重点。