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:
1fatal: The current branch my-awesome-branch has no upstream branch. 2To push the current branch and set the remote as upstream, use 3 4 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:
1git 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
v2.37 we can have Git handle this for us using
1git config --global push.autoSetupRemote true
This updates your global
git configuration and allows
git push to create a remote branch automatically.