git 克隆分支时:在上游源中找不到远程分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32578224/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
When cloning a branch : Remote branch not found in upstream origin
提问by Christofer Hansen
How can I clone a branch from git?
如何从 git 克隆一个分支?
I know it can be a silly thing to ask but I am pretty sure all of us has been there, where we needed to ask a silly question.
我知道问这个问题可能很愚蠢,但我很确定我们所有人都去过那里,我们需要问一个愚蠢的问题。
Now the scenario is - I have a branch named branch-99
and my user name is Christoffer. I try to clone my branch like so:
现在的场景是 - 我有一个名为的分支branch-99
,我的用户名为 Christoffer。我尝试像这样克隆我的分支:
git clone -b branch-99 [email protected]/admin.git
I get this error.
我收到这个错误。
fatal: Remote branch branch-99 not found in upstream origin
致命:在上游源中找不到远程分支 branch-99
How can I clone my branch?
如何克隆我的分支?
回答by Schwern
branch-99
does not exist on the remote repository. You probably misspelled the branch name or the repository.
branch-99
远程存储库中不存在。您可能拼错了分支名称或存储库。
To check which branches exist, clone the repository normally and list the remote branches.
要检查存在哪些分支,请正常克隆存储库并列出远程分支。
git clone [email protected]:Christoffer/admin.git
git branch -r
Alternatively, to avoid having to clone the whole repository just to check for the branches you can use ls-remotes, but you have to init the repository and add the remote manually. Only do this if the repository is huge and you don't intent to use it.
或者,为了避免为了检查分支而必须克隆整个存储库,您可以使用 ls-remotes,但您必须初始化存储库并手动添加远程。仅当存储库很大并且您不打算使用它时才这样做。
git init admin
cd admin
git remote add origin [email protected]:Christoffer/admin.git
git ls-remote --heads origin
To be clear, git clone -b branch-99 [email protected]:Christoffer/admin.git
clones the entire repository. It just checks out branch-99
rather than master
. It's the same as...
需要明确的是,git clone -b branch-99 [email protected]:Christoffer/admin.git
克隆整个存储库。它只是检查branch-99
而不是master
. 这和...
git clone [email protected]:Christoffer/admin.git
git checkout branch-99
That bit of syntax sugar isn't worth the bother. I guess it might save you a tiny bit of time not having to checkout master.
那点语法糖不值得打扰。我想这可能会为您节省一点时间,而不必结帐大师。
If you want to clone just the history of one branch to save some network and disk space use --single-branch
.
如果您只想克隆一个分支的历史记录以节省一些网络和磁盘空间,请使用--single-branch
.
git clone --single-branch -b branch-99 [email protected]:Christoffer/admin.git
However it's usually not worth the trouble. Git is very disk and network efficient. And the whole history of that branch has to be cloned which usually includes most of the repository anyway.
然而,这通常不值得麻烦。Git 对磁盘和网络的效率非常高。并且必须克隆该分支的整个历史记录,这通常包括存储库的大部分内容。
回答by Zepplock
git clone [email protected]:Christoffer/admin.git
git checkout branch-99