1

I created a local repository and I typed:

git branch --set-upstream-to=origin/master

to set up the configuration of how the remote repository's branch connects to the local branch.

git push

works fine.

If I enter:

git config --get-regex branch.master

I get:

branch.master.remote origin
branch.master.merge refs/heads/master

which is what git added to the configuration using:

git branch --set-upstream-to=origin/master

But it turned out that the above command is not necessary. Is that correct?

Other repositories that I created with the same commands and without the above command seem to work fine and they push to the remote without any issues.

Since I think that that configuration is not needed, how do I remove the configuration entries from the affected local repository?

Here are the commands that I used to create all the local repositories (I also used the above command for the afflicted repository):

git init
git add .
git commit -m "Initial commit"
git remote add origin https://...git
Git pull origin master --allow-unrelated-histories
git push origin master

Regards, sp2012

sp2012
  • 133
  • 8
  • 2
    What do you mean by "not necessary"? See [Why do I have to "git push --set-upstream origin "?](https://stackoverflow.com/q/37770467/1256452) and related questions. Use `git branch --unset-upstream` to remove an upstream setting (or two `git config` commands, but one `git branch` is easier). – torek Dec 31 '21 at 11:49
  • Hello torek. Thank you for your comment. By "not necessary", I meant that the repository worked fine, just other repositories where I didn't use the command git branch --set-upstream-to=origin/master. Git branch --unset-upstream worked fine by the way and the entries are now removed from my configuration. By the way, I am new to git, so I don't understand a lot about git. – sp2012 Dec 31 '21 at 12:25
  • 1
    It's a question basically of whether you want to be able to say `git pull`. I never do so I don't usually need an upstream on my branches. You might want to read https://stackoverflow.com/questions/18031946/what-does-set-upstream-do. – matt Dec 31 '21 at 13:32
  • And there is my https://www.biteinteractive.com/picturing-git-conceptions-and-misconceptions/ which talks about saying `git push`. Again, I never really care whether I can say this so I don't usually need an upstream. I'm perfectly happy saying `git push origin @` when I push. – matt Dec 31 '21 at 13:43

1 Answers1

0

Other repositories that I created with the same commands and without the above command seem to work fine and they push to the remote without any issues.

If you have created them with git clone, that command would have clone and checkout the default remote branch, setting the upstream branch in the process.
In that case, no need for git branch -u.

In your case, after a git init, a git push origin master would work, but would not set any upstream tracking reference.

That is why I detailed in "Why do I need to explicitly push a new branch?" that the right command is, for the first push:

git push -u origin master

That would push and do the git branch --set-upstream-to for you.

The next push would be simple git push.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250