til / Automatically creating a remote git branch
If you’ve ever tried pushing a new git branch to a remote host, you’ve probably seen this error:
fatal: The current branch my-awesome-branch has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin my-awesome-branch
This means that there is no corresponding branch on the remote host. To get around this, we can, as the error says, use:
git push -u origin HEAD
This will push the current branch and set the upstream. -u
is the shorthand command for --set-upstream
in the error. HEAD
is a shorter way of telling git
the current branch name, which is handy if you have long branch names.
But, as of git
v2.37
we can have Git handle this for us using autoSetupRemote
.
git config --global push.autoSetupRemote true
This updates your global git
configuration and allows git push
to create a remote branch automatically.