Git Fixes: The Current Branch Has No Upstream Branch
This happens because of your newly created branch. Your Git is not configured to create that same branch on remote. So you are creating that branch only on your local. In order to fix this we need to add more options to our git push command.
Ways to go about solving this issue
There are many ways to solve this issue. The first of them would be to just follow the instructions above.
Find Your Bootcamp Match
- Career Karma matches you with top tech bootcamps
- Access exclusive scholarships and prep courses
Select your interest
First name
Last name
Phone number
By continuing you agree to our Terms of Service and Privacy Policy , and you consent to receive offers and opportunities from Career Karma by telephone, text message, and email.
We caution you to not use this command, why? Because you don’t need to set up an upstream. If you set upstream this way you could have weird and unexpected consequences in your repository. Because of unexpected consequences this option has been deprecated .
There are other ways and as exemplified above we will need to add more options to our git push . For example.
This will automatically create the branch with the same name of your local on remote. The -u creates that branch on the remote repo. If you ever get an error while doing this command just add the —all flag at the end: git push -u origin —all .
Note : You might be tempted to omit -u and just do git push origin <branch-name> . If you don’t add this flag when you do git pull at some point it will not work as expected and Git will give you some additional errors. So do stick to adding the -u .
Configuring Git so you can use git push alone
If you still want to use git push alone without having this error, you’ll need to configure git. There’s a way to always create a remote branch whenever you create a new local branch. We do this with the following command:
With this fix you are good to go to use git push without seeing this error again!
Conclusion
Whenever we work on new branches, most of us have seen this error. We could either configure git to always push to remote as we create the branch or just make that decision ourselves by adding the -u flag to our git push command.
About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.
What’s Next?
Want to take action?
Get matched with top bootcamps
Felipe Bohórquez
About the author: Felipe Bohórquez is a Software Engineer and technical writer at Career Karma. He covers all things frontend and backend development.
Git Branch Upstream
Sometimes people are confused about the difference between git push and git push -u . In this blog post, we will dig into this and try to understand the mechanism behind it.
Examples
Example Base Repo
We assume we are in a repo that already has a master branch both locally and remotely.
Git Push Experiments for Branches
If we are going to create a new branch called temp_1 and push it to the remote branch temp_1 in the remote repo, running the following commands containing git push would fail.
Because the current branch has not been set the upstream branch, so it does not know where the commit should go in the remote repo and will complain to the user. We can validate this by running the following command.
An upstream has to be a remote branch.
However, running the following commands containing git push would actually work.
Even though the current branch does not have an upstream branch, we specifically tell it to push to a branch. If the branch does not exist, it will create a branch for us in the repo.
The drawback of doing this is that next time when you try to push some change to the remote branch, you would still need to type the branch name with git push , which might be tedious.
If we are going to create a new branch called temp_2 based on existing branch temp_1 and push it to the remote branch temp_1 in the remote repo, running the following commands containing git push would update the remote branch temp_1 in the remote repo.
This is because nothing has been updated on the local temp_1 branch, so the remote temp_1 branch is up-to-date.
If we are going to create a new branch called temp_2 and push it to the remote branch temp_2 in the remote repo, running the following commands containing git push -u would work.
We checked the branches created so far.
Next time when you try to push some change to the remote branch, you would just simply do git push without branch name, because the branch already knows what its upstream is.
It should be noted that the following three commands are equivalent:
If we are going to create a new branch called temp_3 based on local branch temp_2 , make some changes, and push it to the remote branch temp_2 in the remote repo, we would need to set the upstream for the local branch temp_3 to remote temp_2 . However, in this scenario, Git does not allow us to do git push without specifying the remote branch specifically, for the branches whose branch names do not match between the local branch and remote branch.
We do git push origin HEAD:temp_2 instead, and it would work.
It should be noted that the local branch temp_2 has not been modified, but the remote branch temp_2 has been modified. This means that the local branch temp_2 has fallen behind the remote branch temp_2 .
We checked the branches created so far.
Branch temp_3 only exists locally but not on the remote server.
Such operation is rare though. Usually, people create branches both locally and remotely and always sync between the local and remote branches. If we want to apply some changes from one branch to another, we would do git merge .
Final Remarks
Although we are using Git every day, it is sometimes hard to understand what is going on behind the Git commands.
How to fix fatal:the current branch master has no upstream branch
Get Educative’s popular interview prep course for free.
The fatal: The current branch master has no upstream branch error occurs when you have not configured git in such a way that it creates a new branch on the remote. Therefore, you are only creating a new branch on the local computer.
Solution
You can fix the issue by typing:
This will fix the error, but only for the current issue. The following is a permanent fix that will automatically create a remote branch:
The command above will fix the error and will always create a remote branch that tracks the local branch.
git fatal: The current branch has no upstream branch
If you see the message “the current branch has no upstream” in your command window, it means you’ve tried to git push to a remote repository from a local branch that has not yet been connected to a remote branch. In other words there is no upstream branch. That means git doesn’t know where to push your changes to. In this post I’ll explain how to set the upstream branch to your local branch.
Please enable JavaScript
‘No upstream branch’ error
If you get an error when you git push, then it could well be because your current branch has not yet been ‘linked’ to a remote branch. The error you see will look like this:

How to set the upstream branch in git
Make sure you are already on the correct local branch, by using git status if you need to check which branch you are already on. Read one of my other posts if you need to use git switch to change branches. Then to set the upstream branch for that local branch, use these flags along with your git push command :
This would set the upstream branch of the current branch to ‘master’. I would always recommend keeping the name of your remote branch exactly the same as your local branch. So if your current local branch was called my-feature-branch then you would type this instead:
What is git push -u ?
Often in git there are several ways of writing each flag. In this scenario:
So these two commands will do exactly the same thing:
For any other information about flags to use with the git push command, read the official git push documentation. Once you’ve set the upstream branch, other commands will automatically use it too without you having to specify the remote branch name. For instance:
If your remote is not called the default name ‘ORIGIN’
What if your remote is not called the default name ‘ORIGIN’? Let’s say it’s called MY-REMOTE, and the branch is called master, then you would type the following command :
Summary
You will now know what to do if you see the message “git fatal: The current branch has no upstream branch”, and have example commands to set the upstream branch in git, no matter what your branch name or remote name.