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

ruf*_*fin 5 git remote-branch git-branch

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

我在git中有一个本地回购,从一个远程仓库中克隆出来development.我在本地分支以在分支中调用新功能newBranchName并调用git push origin newBranchName以在远程仓库上设置新分支.

现在,当我尝试推送时,git似乎正在推动我的newBranchName本地分支进入旧分支跟踪的所有内容.我希望停下来.

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

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
Run Code Online (Sandbox Code Playgroud)

现在,我将编辑该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.
Run Code Online (Sandbox Code Playgroud)

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

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

编辑:这是我的.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
Run Code Online (Sandbox Code Playgroud)

没有关于testingStuff那里的分支.

编辑: 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
Run Code Online (Sandbox Code Playgroud)

AD7*_*six 13

只推动你所在的分支

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

git config push.default upstream # git 1.7.10
git config push.default tracking # older vesions use "tracking" instead of "upstream"
Run Code Online (Sandbox Code Playgroud)

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

停止跟踪远程分支

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

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

[branch "develop"]
    remote = origin
    merge = refs/heads/develop
    rebase = true
Run Code Online (Sandbox Code Playgroud)

而你做到了:

[branch "develop"]
    rebase = true
Run Code Online (Sandbox Code Playgroud)

你的分支机构不再跟踪任何事情.您也可以删除整个部分,git将采取相同的行动.