Git:有没有一种简单的方法来设置新分支来跟踪远程分支?

发布于 2024-10-03 08:37:33 字数 460 浏览 1 评论 0原文

通常的命令是:

git checkout origin/branch_i_want -b branch_i_want

Git 响应:

Branch branch_i_want setup to track remote branch branch_i_want from origin.

这很好。

我的问题很简单。大多数时候,本地创建的分支与远程分支具有相同的名称。是否有 git 命令可以执行此操作,这样我就不需要输入两次分支名称?

换句话说,是否有类似的东西:

git checkout --autocreate-tracking origin/branch_i_want

理论上,这会创建一个名为branch_i_want 的本地分支并将其设置为跟踪 origin/branch_i_want ?

The usual command is:

git checkout origin/branch_i_want -b branch_i_want

Git responds with:

Branch branch_i_want setup to track remote branch branch_i_want from origin.

This is fine.

My question is simple. Most of the time, the locally created branch has the same name as the remote branch. Is there a git command that does this so I do not need to type the branch name twice?

In other words, is there something like:

git checkout --autocreate-tracking origin/branch_i_want

Which would, in theory create a local branch named branch_i_want and set it up to track origin/branch_i_want ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还在原地等你 2024-10-10 08:37:33

使用最近的 git (我认为 >= 1.7),您只需执行 git checkout -t remotename/branchname 即可,并且隐含 -b Branchame

With recent git (I think >= 1.7) you can just do git checkout -t remotename/branchname, and -b branchame is implied.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文