How many times did you try to make
git push for a
- Speed up everyday work with handy Git aliases
- Simpler Git branch first push with no more errors
- Git fast-forward merge – why you should turn it off
No upstream branch error
When we create a new branch and try to push it with
$ git push fatal: The current branch feature-1 has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin feature-1
This means that Git doesn’t know to which remote repository it should push our branch, and how this branch should be named on that remote repository. But then it suggests a solution. Git suspects that we want to push to default remote, called
origin, and name the remote branch exactly the same as a local one.
So we need to copy or write this longer version of the command, suggested in the error message. Since then Git will know that the “upstream” branch for our local one is
git branch -vv
# create new branch git checkout -b feature-1 # push with --set-upstream parameter git push --set-upstream origin feature-1 # show branches and their upstreams git branch -vv
But in most workflows, we will always want to have the remote branch named exactly the same as the local one. So do we really need to repeat ourselves? Even if it’s only one time, when we try to push a new branch, it’s still distractive. And who likes to get errors like this?
Simplifying Git branch first push
To make push simpler, we set the following configuration with a command.
git config --global push.default current
Alternatively, we can do this by adding lines to
~/.gitconfig file to do the same.
[push] default = current
Now, we can create new branch and push it with a little shorter command.
git push -u
-u is a shorter version of
If we push the new branch without the
-u flag, it will work as well. However, when we try to pull changes from it later, we will get a familiar error.
There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details. git pull <remote> <branch> If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/<branch> feature-2
Thankfully, even if we push branch without setting upstream and later get this error on
git push -u at any time. Or by
Thanks to setting a simple configuration option to Git push command we avoid Git errors. Now we are able to push newly created branches with a shorter, easier to remember