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