如何配置git以便我可以直接推送一个分支?

huangapple go评论58阅读模式
英文:

How do I configure git so I can just push a branch?

问题

以下是翻译的内容:

这是我想要的操作:

git checkout -b mybranch
<进行更改>
git commit -m'更改'
git push


我刚刚创建的分支与我所做的更改应存在于远程 origin。此外,当我稍后执行拉取操作时,应拉取相同的分支。

我的当前设置:

```bash
[push]
	default = current
[branch]
	autoSetupMerge = always

我需要做什么来强制使 git 以我想要的方式运行?它曾经在我的当前设置下运行,现在却只显示“everything up to date”,显然这是不正确的,因为此分支不存在于远程。


编辑:显然 pull.default 不是有效的设置,好吧。所以我将其删除了,但这并不是导致不正确行为的原因。

push.default=upstream 设置为危险,因为现在 git checkout -b <newbranch> 出于某种原因会设置分支跟踪自己所分支的位置。因此,如果你在 main 分支上创建一个新分支,main 将成为跟踪分支。而 push.default=upstream 将会将更改合并到 main。这种行为非常糟糕,比 push.default=current 更令人困惑。

英文:

Here's what I want:

git checkout -b mybranch
&lt;make changes&gt;
git commit -m&#39;changes&#39;
git push

The branch I just created with the changes I made to exist on the remote origin. Furthermore, when I later pull, it should pull the same branch.

My current settings:

[push]
	default = current
[branch]
	autoSetupMerge = always

What do I need to do to force git to behave the way I want it to? It used to work with my current settings, now it just says "everything up to date", which clearly it is not because this branch does not exist on the remote.


Edit: Apparently pull.default isn't a valid setting, fine. So I removed it, but that's not causing the incorrect behavior anyway.

Setting push.default=upstream is DANGEROUS since now git checkout -b &lt;newbranch&gt; for some reason sets up where you branched from as the tracking branch. So if you're on main and create a new branch, main is the tracking branch. And push.default=upstream will merge changes to main. This is terrible behavior and bewilderingly more wrong than push.default=current.

答案1

得分: 1

With

[push]
    default = current
    autoSetupRemote = true

git push会自动设置远程分支。

英文:

With

[push]
    default = current
    autoSetupRemote = true

git push will automatically setup the remote branch.

huangapple
  • 本文由 发表于 2023年5月14日 01:15:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76244023.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定