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

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

问题描述

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

I want to be able to do the following:

  1. 基于某个其他(远程或本地)分支(通过 git branchgit checkout -b)创建本地分支

推送本地分支到远程存储库(发布),但让它可跟踪,因此 git pullgit push 将立即生效.

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

我该怎么做?

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

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.

推荐答案

在 Git 1.7.0 及更高版本中,您可以签出新分支:

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

git checkout -b <branch>

编辑文件、添加和提交.然后 使用 -u(--set- 的缩写)推送上游) 选项:

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

git push -u origin <branch>

Git 会在推送过程中设置跟踪信息.

Git will set up the tracking information during the push.

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

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