2

I checkout a new branch

git checkout -b mynewbranch

make some changes and commit them

git add *
git commit -m "Initial commit on this branch"

Then I go to push. Since I haven't set an upstream branch, git informs me I must specify the --set-upstream <remote> <branch> option. I feel like for the past couple years I've been able to just do

git push -u

and if my current branch doesn't exist on origin, it creates one with the same name and pushes to that with no further fuss. But I've recently reinstalled git and now when I run git push -u it continues to complain about there being no upstream branch.

I've found that I can modify the setting of push.default to make push automatically do what I expect even the -u option by setting it to current, but I like having to specify the -u so I know when I'm setting up that tracking information. However, I would like -u to automatically use my current branch name if I don't specify it.

What option can I set to make -u behave as I recall it?

EDIT: The actual error message I'm receiving is

$> git push -u
fatal: The current branch mynewbranch has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin mynewbranch

UPDATE: With further testing, it appears that this may happen only with private repos. I've noticed when using public repos on GitHub -u may be sufficient, but when in private GitHub repos or repos on AWS CodeCommit, I get the error listed above.

Shaun Hamman
  • 2,287
  • 4
  • 21
  • 33
  • 1
    Your question title / subject refers to `git pull`, but the body refers to `git push`. Is the title just wrong? – torek Aug 01 '18 at 18:53
  • 1
    did you add a remote first using `git remote add` before pushing ? – Jaspreet Singh Aug 01 '18 at 19:11
  • @torek - Yep, typo in the title. Fixed. – Shaun Hamman Aug 01 '18 at 19:23
  • @Jaspreet Singh - Yes, an origin remote has been added and in this case is the only remote. I could understand this behavior if there were multiple remotes I suppose, but in that case I would only expect to have to provide the remote name and not the branch (leaving that to be implied by the current branch name I'm on). – Shaun Hamman Aug 01 '18 at 19:24
  • 1
    Refer this https://stackoverflow.com/questions/6089294/why-do-i-need-to-do-set-upstream-all-the-time – Jaspreet Singh Aug 01 '18 at 19:29
  • @Jespreet Singh - Yes, that question refers to why `--set-upstream` is necessary, and mentions that `-u` is the shorthand version of that, but it doesn't detail anything regarding `-u` inferring the remote and/or branch. One of the answers does mention setting push.default to current, but that suppresses the error when not using `-u` prior to setting up upstream tracking, which isn't the behavior I remember. – Shaun Hamman Aug 01 '18 at 19:42
  • Perhaps I'm mistaken on that though, and `push.default` being set to `current` is what I'm recalling. I know I have never changed this option though, so did the default value change at some point? I have found no reference to say it did (at least, not to/from `current`. It seems to have changed from `matching` to `simple` in Git 2.0, but neither of those having the behavior I'm looking for). – Shaun Hamman Aug 01 '18 at 19:49
  • 1
    OK: if you have a typical setup, and a modern (2.0 or later) Git, and leave `git config push.default` set to its default of `simple`, `git push -u` should Just Work the way you want. Is `push.default` set to something unusual? What other unusual settings do you have? What version of Git are you using? – torek Aug 01 '18 at 19:50
  • @torek - My `push.default` is presently unset (so presumably `simple`, I unset it after playing with some different values). Git version is `git version 2.18.0.windows.1`. The only unusual setting I have is that I have `user.useConfigOnly=true`, but I've tried resetting that to default and it doesn't seem to affect this behavior. – Shaun Hamman Aug 01 '18 at 20:25
  • 1
    Interesting. It really seems like it should be working, then, unless someone broke something in 2.18.0.windows.1. – torek Aug 01 '18 at 20:26
  • I do see that the `--set-upstream` flag has been removed (looks like in 2.15 maybe) and that `--set-upstream-to` is the replacement. Given that the error message I'm receiving is referring to the former, is it possible this is some minor functionality difference between the two, and where `-u` used to map to `--set-upstream` it now maps to `--set-upstream-to`? – Shaun Hamman Aug 01 '18 at 20:46

1 Answers1

2

I do see that the --set-upstream flag has been removed (looks like in 2.15 maybe) and that --set-upstream-to is the replacement.

It was actually with Git 1.8: see here and git 1.8.0 announce:

"git branch --set-upstream" is deprecated and may be removed in a relatively distant future.
"git branch [-u|--set-upstream-to]" has been introduced with a saner order of arguments.

git push uses that same -u shortcut.

I always seen git push -u used with arguments:

git push -u origin myBranch

Once that is done, the next pushes will use simply: git push.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • It was deprecated in 1.8, but it was actually removed in 2.15.0. https://github.com/git/git/blob/master/Documentation/RelNotes/2.15.0.txt – Shaun Hamman Aug 01 '18 at 21:58