Git establishes the connection between the local branch and the remote branch when pushing

Problems encountered when doing git push:
fatal: The current branch adf has no upstream branch.
Checked the relationship between the local branch and the remote branch, and found that the local branch newdev is not associated with the remote branch.
dev b57ad4a [origin/dev] a new commit
master acad15e [origin/master: ahead 1, behind 3] still 2 commit
* newdev b57ad4a a new commit
newdev2 b57ad4a [origin/dev] a new commit
remotes/origin/HEAD -> origin/master
remotes/origin/dev b57ad4a a new commit
remotes/origin/master d637b60 1111111

OK, let's load it up below.
git push --set-upstream origin newdev:dev
The above command means to associate the local newdev branch with the remote origin/dev branch.

dev b57ad4a [origin/dev] a new commit
master acad15e [origin/master: ahead 1, behind 3] still 2 commit
* newdev b57ad4a [origin/dev] a new commit
remotes/origin/HEAD -> origin/master
remotes/origin/dev b57ad4a a new commit
remotes/origin/master d637b60 1111111

The result is shown above.
When doing git push, two things need to be determined.
1. Whether the local branch and the remote branch are related
2. Check whether the name of the local branch is the same as the name of the remote branch.

If the local branch and the remote branch are not related, it is best to do so (you can view it through the git branch -avv command), because this will search for the relationship in the follow-up. If multiple functions are developed in parallel, the corresponding branching problem.

When the local branch and the remote branch are related, it depends on whether the local branch and the remote branch have the same name.
If the name is the same, then you can submit git push directly like this If the name is different, you need to submit like this
git push origin HEAD:dev


其实正常在使用的时候直接git checkout -b newdev2 origin/dev
dev b57ad4a [origin/dev] a new commit
master acad15e [origin/master: ahead 1, behind 3] still 2 commit
newdev b57ad4a [origin/dev] a new commit
* newdev2 b57ad4a [origin/dev] a new commit
remotes/origin/HEAD -> origin/master
remotes/origin/dev b57ad4a a new commit
remotes/origin/master d637b60 1111111

这样就可以迅速的建立一个本地分支和远程分支的关联。


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325641180&siteId=291194637