在网上一篇文章上看到,git push操作的完整命令是:
“git push <远程主机名> <本地分支名>:<远程分支名>”
文章的作者还说了,“如果省略远程分支名,则表示将本地分支推送与之存在"追踪关系"的远程分支(通常两者同名),如果该远程分支不存在,则会被新建。
$ git push origin master
上面命令表示,将本地的master分支推送到origin主机的master分支。如果后者不存在,则会被新建。
”
我在本地新建仓库“bendi”,github上新建远程仓库“origin”,然后本地仓库push到远程。
没有设置set-upstream,并且第一次push的时候也没加-u参数,而是直接“git push origin master”。
问题:现在本地仓库“bendi”和远程仓库“origin”之间应该没有“追踪关系”把,为什么我还是可以通过“git push origin master”这种不带远程分支名的命令来push到远程呢?bendi和origin这2个仓库没有设置过追踪关系啊。
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 thelocalmaster 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