如何将新的本地分支推送到远程Git存储库并进行跟踪? [英] How do I push a new local branch to a remote Git repository and track it too?

查看:193
本文介绍了如何将新的本地分支推送到远程Git存储库并进行跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够做到以下几点:


  1. 创建基于其他一些本地分支(远程或本地)分支(通过 git branch git checkout -b


  2. 将本地分支
    推送到远程存储库(发布),但将其作为
    可跟踪的,以便 git pull git push 将立即生效。

  3. / p>

    我知道Git 1.7中的 - set-upstream ,但这是一个后期创建操作。我希望找到一种方法在将分支推送到远程存储库时进行类似的更改。

    解决方案

    在Git 1.7.0以后,你可以签出一个新的分支:

      git checkout -b< branch> 

    编辑文件,添加并提交。然后使用 -u (简写为 - set-upstream 选项:

      git push -u起源<分支> 

    Git会在推送期间设置跟踪信息。


    I want to be able to do the following:

    1. Create a local branch based on some other (remote or local) branch (via git branch or git checkout -b)

    2. Push the local branch to the remote repository (publish), but make it trackable so git pull and git push will work immediately.

    How do I do that?

    I know about --set-upstream in Git 1.7, but that is a post-creation action. I want to find a way to make a similar change when pushing the branch to the remote repository.

    解决方案

    In Git 1.7.0 and later, you can checkout a new branch:

    git checkout -b <branch>
    

    Edit files, add and commit. Then push with the -u (short for --set-upstream) option:

    git push -u origin <branch>
    

    Git will set up the tracking information during the push.

    这篇关于如何将新的本地分支推送到远程Git存储库并进行跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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