github - 请教一个问题,关于 “git push 远程仓库名 本地分支:远程分支” 。
给我你的怀抱
给我你的怀抱 2017-05-02 09:41:14
0
3
627

在网上一篇文章上看到,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个仓库没有设置过追踪关系啊。

给我你的怀抱
给我你的怀抱

reply all (3)
Ty80

This should not be difficult to explain.

If you have executedgit remote addin the current folder, the command should be

git 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 usegit cloneto clone the remote library, it should automatically set the origin pointer for you.

But there is one thing you should pay attention to. . Theoriginmentioned 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 isgit remote add origin https://github.com/yourName/Angular-Table.git。这样一来,你就可以用git push origin masterto 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 throughgit branch来查看本地有什么branch。也可以通过git remote -v来查看远程有什么 branch。顺便,git remote -v, give it a try

    小葫芦

    Check if there is a master branch remotely, maybe you have submitted to this branch

      为情所困

      You can run the following command to view the branchesupstream

      git branch -vv

      This article should be helpful to you

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!