什么是`git push origin master`?帮助与git的裁判,头和遥控器 [英] What is `git push origin master`? Help with git's refs, heads and remotes

查看:179
本文介绍了什么是`git push origin master`?帮助与git的裁判,头和遥控器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 git push origin master 的问题:


  • 我知道 origin 是远程的(又名GitHub)
  • git push origin master 相同> git push origin master_on_my_machine:master_on_github



I don '不知道是否:


$ li $ $ c $ master_on_my_machine 等于 / refs / heads / master

  • master_of_github 等于 / refs /


    如果它相等,应该可以做

  • code> git push origin refs / heads / master:refs / heads / origin / master



    最后,我想要do:只有当
    > b 时,

  • 我在主分支上

  • 我想从github上的my_test分支进行推拉操作,只需键入 git push git pull 。 local

    解决方案

    c>和远程。如果你想使用 git pull git push ,你必须告诉你的本地分支( my_test )它跟踪哪个远程分支。在典型的Git中,这可以在配置文件和命令中完成。



    命令



    请确保您的 master 分支中包含 $ b <1> git checkout master



    然后用
    <2>创建新分支 git branch --track my_test origin / my_test



    然后用
    <3> git checkout my_test



    然后你可以 push pull ,而无需指定哪个本地和远程。



    然而,如果您已经创建了分支,那么您可以使用 -u 开关告诉git的 push pull 你想从现在开始使用指定的本地和远程分支,如下所示:



    $ p $ g $ git pull -u my_test origin / my_test $ b $ git push -u my_test origin / my_test
    code>

    配置

    要设置的命令远程分支跟踪相当直接,但我列出了配置方式,以及如果我设置了一堆跟踪分支,我发现它更容易。使用您最喜欢的编辑器打开您的项目的 .git / config ,并将以下内容添加到底部。

      [remoteorigin] 
    url = git@github.com:username / repo.git
    fetch = + refs / heads / *:refs / remotes / origin / *
    [branchmy_test]
    remote = origin
    merge = refs / heads / my_test

    这指定了一个名为 origin 的远程,在本例中为GitHub样式,然后告诉分支 my_test 将它作为远程使用。



    在运行上述命令后,您可以在配置中找到与此类似的东西。



    一些有用的资源:


    I have a question about what git push origin master does:

    • I know that origin is the remote (aka GitHub)
    • git push origin master is the same as git push origin master_on_my_machine:master_on_github

    I don't know if:

    • master_on_my_machine is equal to /refs/heads/master
    • master_of_github is equal to /refs/remotes/origin/master

    If it's equal, should it be possible to do git push origin refs/heads/master:refs/heads/origin/master?

    Finally, what I want to do is only type git push and git pull when:

    • I'm on a master branch
    • I want to push and pull from a my_test branch on github, only typing git push and git pull.

    解决方案

    Git has two types of branches: local and remote. To use git pull and git push as you'd like, you have to tell your local branch (my_test) which remote branch it's tracking. In typical Git fashion this can be done in both the config file and with commands.

    Commands

    Make sure you're on your master branch with

    1)git checkout master

    then create the new branch with

    2)git branch --track my_test origin/my_test

    and check it out with

    3)git checkout my_test.

    You can then push and pull without specifying which local and remote.

    However if you've already created the branch then you can use the -u switch to tell git's push and pull you'd like to use the specified local and remote branches from now on, like so:

    git pull -u my_test origin/my_test
    git push -u my_test origin/my_test
    

    Config

    The commands to setup remote branch tracking are fairly straight forward but I'm listing the config way as well as I find it easier if I'm setting up a bunch of tracking branches. Using your favourite editor open up your project's .git/config and add the following to the bottom.

    [remote "origin"]
        url = git@github.com:username/repo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
    [branch "my_test"]
        remote = origin
        merge = refs/heads/my_test
    

    This specifies a remote called origin, in this case a GitHub style one, and then tells the branch my_test to use it as it's remote.

    You can find something very similar to this in the config after running the commands above.

    Some useful resources:

    这篇关于什么是`git push origin master`?帮助与git的裁判,头和遥控器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆