How to stop clicking on multiple remote branches in git? (aka, How to disable remote git branches?)

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

I have a local repo in git cloned from a remote repo, development . I am deploying locally to play branches with a new function named newBranchName and call git push origin newBranchName to set up a new branch on the remote repo.

Now when I try to push, git seems to push the local branch newBranchName on everything that the old branch was tracking. I want this to stop.

Here is an extended sample of what I mean. I am going to create a local branch, add a file, commit locally, and then click on 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 will edit the test.txt file, commit the change and click. It bothers me.

 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 (eg 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details. 

I want to continue push to testingStuff remotely, but I want to stop pressing remoteTrackedByOldBranch when I type git push . I don’t want to delete any branch - it seems that a number of answers to such questions involve deleting, not the absence of tracking. I also don't want to know how to click on a particular branch, only explicitly calling it in the git push command. Too many memory errors with muscles. I want git push click only origin/testingStuff .

I have already silently (a word that proves itself) hammered my .git / config, trying to execute this, and it still clicks on remoteTrackedByOldBranch .

EDIT: This is what my .git / config file looks like after doing the above:

 [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.

EDIT: git branch -avv output:

 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 
+4
source share
2 answers

Click only the branch you are on.

By default, git will pop all your tracking branches whenever you issue git push with no arguments. to make it only by clicking on the branch you are on.

 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 this - you can use the -global switch or just edit the ~ / .gitconfig file depending on.

Stop remote branch tracking

git config is just a file. Quite often, the easiest way to examine and fix git configurations is to simply open the .git / config file and edit it

eg. if your .git / config file has a section like this:

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

and you will do this:

 [branch "develop"] rebase = true 

your nolonger branch is tracking anything. You can also just delete the entire section, and git will act the same.

+12
source

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

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

And you can remove the configuration as follows:

 git config --remove-section branch.remoteTrackedByOldBranch 

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

After this change, git push no longer needs to try to drag this branch to the remote computer.

+3
source

Source: https://habr.com/ru/post/1412625/


All Articles