如何检出远程Git分支? [英] How do I check out a remote Git branch?
问题描述
有人用 git push origin test
将名为 test
的分支推送到共享存储库。我可以看到带有 git branch -r
的分支。
现在我试图检查远程<
$ b
-
git checkout test
它什么都不做 $ c> git checkout origin / test 给出
*(no branch)
。这是令人困惑的。
更新
Jakub的回答实际上改善了这一点。使用Git版本≥ 1.6.6,你可以这样做:
git fetch
$ b
git checkout test
(用户masukomi指出下面
git checkout test
在现代git中不起作用如果你有多个遥控器,在这种情况下,使用git checkout -b test<远程名称> / test
)。
老的答案
在你开始在远程分支本地工作之前,你需要按照下面的回答中的提示取出它。
要获取分支,您只需要:
git获取源
这将为您获取所有远程分支。您可以看到可用于结帐的分支:
git分支-v -a
在远程分支机构中,您现在需要查看您感兴趣的分支,并为您提供本地工作副本:
git checkout -b测试源/测试
Somebody pushed a branch called
test
withgit push origin test
to a shared repository. I can see the branch withgit branch -r
.Now I'm trying to check out the remote
test
branch.I've tried:
git checkout test
which does nothinggit checkout origin/test
gives* (no branch)
. Which is confusing. How can I be on "no branch"?
How do I check out a remote Git branch?
Update
Jakub's answer actually improves on this. With Git versions ≥ 1.6.6, you can just do:
git fetch
git checkout test
(User masukomi points out below that git checkout test
will NOT work in modern git if you have multiple remotes. In this case use git checkout -b test <name of remote>/test
).
Old Answer
Before you can start working locally on a remote branch, you need to fetch it as called out in answers below.
To fetch a branch, you simply need to:
git fetch origin
This will fetch all of the remote branches for you. You can see the branches available for checkout with:
git branch -v -a
With the remote branches in hand, you now need to check out the branch you are interested in, giving you a local working copy:
git checkout -b test origin/test
这篇关于如何检出远程Git分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!