JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM > Git >

Fatal: The Current Branch Master Has No Upstream Branch error in Git

Author:JIYIK Last Updated:2025/03/30 Views:

This article outlines different methods we can use to resolve the Fatal: The Current Branch Master Has No Upstream Branch error. We usually encounter this error when we create a new local branch, make some commits, and try to push to the remote repository.

By default, Git is not configured to create corresponding branches in the remote repository when we create them in the local repository.

Let’s look at three methods you can use to fix the error.

Fix the Fatal: The Current Branch Master Has No Upstream Branch error

For the sake of a simple walkthrough, we'll simulate a scenario where we get the fatal: Current branch master has no upstream branches error on Git by creating a new branch in our local repository, making some commits and trying to push.

$ git checkout -b Dev2.1

We have made some changes and committed them. Let's try pushing to the remote repository

$ git push

fatal error after git push

Here are three methods we can use to fix this error.

The first method is the one recommended by Git. However, we strongly discourage its use as we will see shortly, but first let’s see how this command works.

To resolve the error we will run:

$ git push --set-upstream origin Dev2.1

git push set upstream

This command sets up the Dev2.1 branch in our remote repository, which will track the local branch. However, this approach may cause unexpected and strange consequences in your repository.

Let's look at the second method.

You can also use:

$ git push -u origin Dev2.1

This command will create a remote branch with the same name as your local branch. If you encounter errors, add the all flag to the command as shown below.

$ git push -u origin --all

We prefer using the -u flag instead of git push --set-upstreamthe command.

The above methods solve the current problem. What if we want a permanent solution?

Fortunately, Git is very malleable; we can tweak the Git configuration files to get a permanent solution, which brings us to the third approach.

Run the following command to configure Git to create remote branches when we create local branches.

$ git config --global push.default current

We can now use git pushthe command alone without having to deal with this annoying error again.

To summarize, when we created a local branch, we did not configure Git to create a corresponding remote branch, and we got the fatal: The current branch master has no upstream branch error.

We have covered various methods that you can use to fix this error. You now know what to avoid.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Changing drives in Git Bash

Publish Date:2025/03/30 Views:56 Category:Git

This short article will discuss how we can use Git Bash to have a Unix-style command line environment in Windows operating system and run multiple commands in this terminal. Git Bash Git is a collection of command-line utilities created to

Adding a remote branch in Git

Publish Date:2025/03/30 Views:142 Category:Git

Git does not allow its developers to create new branches on remote repositories. But instead, we can push an already existing local branch, and after doing so, we can bring it to the remote repository using some Git commands. In every versi

Synchronize your local repository with a remote repository in Git

Publish Date:2025/03/30 Views:92 Category:Git

This article outlines the process of syncing your local repository with a remote repository. We will also see how to sync a GitHub branch with a remote repository on the command line. Synchronize your local repository with a remote reposito

Creating a remote repository from a local repository in Git

Publish Date:2025/03/30 Views:105 Category:Git

This article discusses the necessary steps to create a remote repository based on a local repository. This is ideal when you have a local repository that needs to be available on a remote or SSH-enabled server. Creating a remote repository

Removing the upstream repository in Git

Publish Date:2025/03/30 Views:177 Category:Git

This article will teach you how to delete an upstream repository in Git. We may sometimes need to delete or change the remote repository that we use with our local repository. To do this, we can use the Git command git remote . Removing the

Git remote add SSH

Publish Date:2025/03/30 Views:53 Category:Git

In this day and age, the most widely used version control system is Git, which is operated by most developers within a team structure. This is mainly used to increase code efficiency, no matter how big or critical the project is. In this se

Differences between Git Reset, Revert and Checkout commands

Publish Date:2025/03/30 Views:185 Category:Git

This article discusses the differences between the git reset , , git revert and git checkout commands. These are some of the most useful Git utilities that allow us to undo certain changes in our repository. It’s easy to get confused with

Git revert local commits

Publish Date:2025/03/30 Views:84 Category:Git

When a software engineer or a web developer uses Git, it is obvious that he pushes a lot of code and commits to the Git repository every day, and while doing so, the need to undo or revert a particular commit or a set of commits arises from

Deleting local and remote Git branches

Publish Date:2025/03/30 Views:146 Category:Git

Git comes into play in version control systems when you are working with a team and the entire team is making changes to the same code repository. Creating a new branch in Git is relatively easy than other version control systems and deleti

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial