如何停止在git中推送到多个远程分支? (又名,如何解开远程git分支?)

时间:2022-06-05 07:26:00

Tried to use what's here, but that doesn't solve things for me.

试图使用这里的东西,但这并不能解决我的问题。

I've got a local repo in git, cloned from a remote repo, development. I branch locally to play around with a new feature in a branch called newBranchName and call git push origin newBranchName to set up the new branch on the remote repo.

我在git中有一个本地回购,从远程仓库克隆开发。我在本地分支以在名为newBranchName的分支中使用新功能,并调用git push origin newBranchName以在远程仓库上设置新分支。

Now when I try to push, git seems to be pushing my newBranchName local branch into everything the old branch tracked as well. I want that to stop.

现在,当我尝试推送时,git似乎将我的newBranchName本地分支推送到旧分支跟踪的所有内容中。我希望停下来。

Here's an extended sample of what I mean. I'm going to create a local branch, add a file, commit locally, then push to a new branch on the remote server. So far, so good.

这是我的意思的扩展样本。我将创建一个本地分支,添加一个文件,在本地提交,然后推送到远程服务器上的新分支。到现在为止还挺好。

Administrator@BOXEN /path/to/working/dir (oldBranch)
$ git branch testingStuff

Administrator@BOXEN /path/to/working/dir (oldBranch)
$ git checkout testingStuff
Switched to branch 'testingStuff'

Administrator@BOXEN /path/to/working/dir (testingStuff)
$ vim test.txt

Administrator@BOXEN /path/to/working/dir (testingStuff)
$ git add test.txt

Administrator@BOXEN /path/to/working/dir (testingStuff)
$ git commit -a
[testingStuff 11468d8] Testing git; can trash this branch.
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 test.txt

Administrator@BOXEN /path/to/working/dir (testingStuff)
$ git push origin testingStuff
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 299 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To http://url/to/remote/repo.git
 * [new branch]      testingStuff -> testingStuff

Now, I'll edit that test.txt file, commit the change, and push. This is what confuses me.

现在,我将编辑该test.txt文件,提交更改并推送。这让我很困惑。

Administrator@BOXEN /path/to/working/dir (testingStuff)
$ vim test.txt

Administrator@BOXEN /path/to/working/dir (testingStuff)
$ git commit -a
[testingStuff 2be7063] more testing git
 1 files changed, 1 insertions(+), 0 deletions(-)

Administrator@BOXEN /path/to/working/dir (testingStuff)
$ git push
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 276 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To http://url/to/remote/repo.git
   11468d8..2be7063  testingStuff -> testingStuff
 ! [rejected]        oldBranch -> remoteTrackedByOldBranch (non-fast-forward)
error: failed to push some refs to 'http://url/to/remote/repo.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

I want to continue pushing to testingStuff remotely, but want to stop pushing to remoteTrackedByOldBranch when I type git push. I don't want to delete any branch -- seems a number of answers to similar questions suggest deleting rather than untracking. Nor do I want to know how to push to a specific branch only by explicitly naming it in the git push command. Too many muscle-memory mistakes that way. I want git push to push to origin/testingStuff only.

我想继续远程推送到testingStuff,但是当我输入git push时想要停止推送到remoteTrackedByOldBranch。我不想删除任何分支 - 似乎对类似问题的一些答案建议删除而不是未跟踪。我也不想知道如何通过在git push命令中明确命名来推送到特定分支。那种肌肉记忆错误太多了。我希望git push只推送到origin / testingStuff。

I've already unsmartly (a word which proves itself) butchered my .git/config trying to accomplish this, and it's still pushing to remoteTrackedByOldBranch.

我已经不熟悉了(一个证明自己的词),但是我的.git / config试图完成这个,并且它仍然在推动remoteTrackedByOldBranch。

EDIT: Here's what my .git/config file looks like after doing the above:

编辑:这是我的.git / config文件在执行上述操作后的样子:

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
        hideDotFiles = dotGitOnly
[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = http://url/to/remote/repo.git
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branch "oldBranch"]
        remote = origin
        merge = refs/heads/oldBranch

Nothing about the testingStuff branch in there.

没有关于那里的testingStuff分支。

EDIT: git branch -avv output:

编辑:git branch -avv输出:

Administrator@BOXEN /path/to/working/dir (testingStuff)
$ git branch -avv
  master                                 721aa61 initial setup
  projectFork1                           e132f5f Fixed Construction grid labels getting sliced.
  projectFork2                           1d20317 initial load
  oldBranch                              1d20317 initial load
* testingStuff                           192f622 Still testing
  remotes/origin/HEAD                    -> origin/master
  remotes/origin/empty                   ec1c694 initial setup
  remotes/origin/joeUserFork1            771f43e Initial Load
  remotes/origin/master                  721aa61 initial setup
  remotes/origin/projectFork1            e132f5f Fixed Construction grid labels getting sliced.
  remotes/origin/oldBranch               1d20317 initial load
  remotes/origin/joeUserFork2            dc605e8 What was sent initially.
  remotes/origin/testingStuff            192f622 Still testing
  remotes/origin/upload_master           0d8c440 Initial Load

2 个解决方案

#1


12  

Only push the branch you're on

只推动你所在的分支

By default, git will push all of your tracking branches whenever you issue a git push with no arguments. to make it only push the branch you're on

默认情况下,每当您发出不带参数的git push时,git都会推送所有跟踪分支。使它只推动你所在的分支

git config push.default upstream # git 1.7.10
git config push.default tracking # older vesions use "tracking" instead of "upstream"

if you want git to always work like that - you can use the --global switch or simply edit your ~/.gitconfig file to suit.

如果你希望git始终像这样工作 - 你可以使用--global开关或只是编辑〜/ .gitconfig文件以适应。

Stop tracking a remote branch

停止跟踪远程分支

git's config is just a file. Quite often the easiest way to investigate and or fix your git config - is simply to open your .git/config file and edit it

git的配置只是一个文件。通常最简单的方法来调查和修复您的git配置 - 只需打开您的.git / config文件并进行编辑

e.g. if you have a section like this in your .git/config file:

例如如果你的.git / config文件中有这样的部分:

[branch "develop"]
    remote = origin
    merge = refs/heads/develop
    rebase = true

and you make it:

而你做到了:

[branch "develop"]
    rebase = true

your branch nolonger tracks anything. You can also just delete the whole section and git will act the same.

你的分支不再追踪任何东西。你也可以删除整个部分,git将采取相同的行动。

#2


3  

The tracking relationship with a remote branch is maintained in the branch.<BRANCHNAME>.remote and branch.<BRANCHNAME>.merge configuration items associated with a particular branch. You can see the current configuration like this:

与远程分支的跟踪关系在分支中维护。 .remote and branch。 .merge与特定分支关联的配置项。你可以看到这样的当前配置:

git config --get-regexp 'branch.remoteTRackedByOldBranch.*'

And you can delete the configuration like this:

你可以删除这样的配置:

git config --remove-section branch.remoteTrackedByOldBranch

[Note that this will remove all the configuration associated with this branch, but it is unlikely there is anything other than the remote and merge settings. You can obviously accomplish the same thing by hand-editing the .git/config file.]

[请注意,这将删除与此分支关联的所有配置,但除了远程和合并设置之外,不太可能存在任何其他配置。显然,您可以通过手动编辑.git / config文件来完成同样的事情。

After this change git push should no longer attempt to push that branch to a remote.

在此更改之后,git push应该不再尝试将该分支推送到远程。

#1


12  

Only push the branch you're on

只推动你所在的分支

By default, git will push all of your tracking branches whenever you issue a git push with no arguments. to make it only push the branch you're on

默认情况下,每当您发出不带参数的git push时,git都会推送所有跟踪分支。使它只推动你所在的分支

git config push.default upstream # git 1.7.10
git config push.default tracking # older vesions use "tracking" instead of "upstream"

if you want git to always work like that - you can use the --global switch or simply edit your ~/.gitconfig file to suit.

如果你希望git始终像这样工作 - 你可以使用--global开关或只是编辑〜/ .gitconfig文件以适应。

Stop tracking a remote branch

停止跟踪远程分支

git's config is just a file. Quite often the easiest way to investigate and or fix your git config - is simply to open your .git/config file and edit it

git的配置只是一个文件。通常最简单的方法来调查和修复您的git配置 - 只需打开您的.git / config文件并进行编辑

e.g. if you have a section like this in your .git/config file:

例如如果你的.git / config文件中有这样的部分:

[branch "develop"]
    remote = origin
    merge = refs/heads/develop
    rebase = true

and you make it:

而你做到了:

[branch "develop"]
    rebase = true

your branch nolonger tracks anything. You can also just delete the whole section and git will act the same.

你的分支不再追踪任何东西。你也可以删除整个部分,git将采取相同的行动。

#2


3  

The tracking relationship with a remote branch is maintained in the branch.<BRANCHNAME>.remote and branch.<BRANCHNAME>.merge configuration items associated with a particular branch. You can see the current configuration like this:

与远程分支的跟踪关系在分支中维护。 .remote and branch。 .merge与特定分支关联的配置项。你可以看到这样的当前配置:

git config --get-regexp 'branch.remoteTRackedByOldBranch.*'

And you can delete the configuration like this:

你可以删除这样的配置:

git config --remove-section branch.remoteTrackedByOldBranch

[Note that this will remove all the configuration associated with this branch, but it is unlikely there is anything other than the remote and merge settings. You can obviously accomplish the same thing by hand-editing the .git/config file.]

[请注意,这将删除与此分支关联的所有配置,但除了远程和合并设置之外,不太可能存在任何其他配置。显然,您可以通过手动编辑.git / config文件来完成同样的事情。

After this change git push should no longer attempt to push that branch to a remote.

在此更改之后,git push应该不再尝试将该分支推送到远程。