Git报错:fatal: The current branch main has no upstream branch

Git报错:fatal: The current branch main has no upstream branch

Reference: https://blog.csdn.net/benben_2015/article/details/78803753

question

When pushing the code, the reason for the "git master branch has no upstream branch" problem is that the local branch is not associated with the branch of the remote warehouse. As shown in the figure below:

Specific reasons: This situation occurs mainly because there are too many remote warehouses and many branches. By default, git push is generally uploaded to the master branch under origin. However, when there are too many repositories and branches and no association is set, git will have doubts because it cannot judge your push target.

Git's "master" branch is not a special branch. It is completely indistinguishable from other branches. The reason almost every repository has a master branch is because the git init command creates it by default, and most people don't bother to change it.
The remote repository name "origin" does not have any special meaning in Git, just like the branch name "master". origin" is the default remote repository name when you run git clone. If you run git clone -o booyah, then your default remote branch name will be booyah/master.

solution

The solution is actually to determine these two values. There are two methods:

The first one is as prompted in the figure above: git push --set-upstream origin master . The origin is the label that git creates for you to point to the remote code base when you clone the remote code, which points to the repository. In order to clearly understand the repository you want to point to, you can use the command git remote -v to view it. master is your remote branch, you can use git branch -a to view all branches, and the remote branch is the red part. Then after determining these two values, just replace the values.
Another way is: git push -u origin master . Also replace origin and master according to your own needs.
The difference between the two commands is that the first command is to ensure that your remote branch exists, and if it does not exist, it cannot be associated. Even if the second instruction does not have the branch you want to associate remotely, it will automatically create one to achieve association.

Guess you like

Origin blog.csdn.net/m0_52910424/article/details/127697655
Recommended