I saw in an online article that the complete command for git push operation is:
"git push <remote host name> <local branch name>:<remote branch name>"
The author of the article also said, "If omit the remote branch name , it means that the local branch will be pushed to the remote branch with which there is a "tracking relationship" (usually both have the same name) ), if the remote branch does not exist, it will be created
.$ git push origin master
The above command means pushing the local master branch to the master branch of the origin host. If the latter does not exist, it will be created.
”
I created a new local warehouse "bendi", a new remote warehouse "origin" on github, and then pushed the local warehouse to the remote.
Set-upstream is not set, and the -u parameter is not added when pushing for the first time, but "git push origin master" directly.
Question: There should be no "tracking relationship" between the local warehouse "bendi" and the remote warehouse "origin". Why can I still pass "git push origin master" which does not What about the command with remote branch name to push to the remote? The two warehouses bendi and origin have no tracking relationship set up.
This should not be difficult to explain.
If you have executed
git remote add
in the current folder, the command should begit remote add origin https://github.com/yourName/yourRepo.git
Usually it’s like this. . In this way, origin points to your remote library. You can try removing origin from that command and you should get an error. If you use
git clone
to clone the remote library, it should automatically set the origin pointer for you.But there is one thing you should pay attention to. . The
origin
mentioned so far is not the warehouse name. . Instead, it is an alias given to the remote warehouse locally.In your case, you said you want to "create a new remote warehouse 'origin' on github", I'm a little confused==! The warehouse name is generally not called origin . . For example, if your project is called Angular-Table, then all you need to do is
git remote add origin https://github.com/yourName/Angular-Table.git
。这样一来,你就可以用git push origin master
to push the changes.Let’s talk about branch.
git push origin master
意思就是,把你本地的 master branch 推送到远程 origin。如果写成git push origin master:foo
, which means pushing the local master branch to the remote foo branch.By the way, here comes a black technology. . For example, if I want to delete the remote foo branch, the command is:
git push origin :foo
You can view remote information through
git branch
来查看本地有什么branch。也可以通过git remote -v
来查看远程有什么 branch。顺便,git remote -v
, give it a tryCheck if there is a master branch remotely, maybe you have submitted to this branch
You can run the following command to view the branches
upstream
This article should be helpful to you