GIT:如何正确地将远程分支下载到本地?
想要下载另一个远程分支进行维护,然后再推回去。
所以我尝试了:
git switch another_branch
fatal: invalid reference: another_branch
尝试过:
git checkout --track origin/another_branch
fatal: 'origin/another_branch' is not a commit and a branch 'another_branch' cannot be created from it
尝试过:
git checkout another_branch
error: pathspec 'another_branch' did not match any file(s) known to git
尝试过:
git fetch origin another_branch:another_branch
From gitlab.my-inc.com:projname/proj
* [new branch] another_branch -> another_branch
git checkout another_branch
Switched to branch 'another_branch'
看起来不错但是:
git pull
fatal: refusing to merge unrelated histories
git branch -vv
* another_branch 421f45e normal commit comments
git branch --set-upstream-to origin/another_branch
error: the requested upstream branch 'origin/another_branch' does not exist
hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.
所以,我尝试过:
git fetch
git fetch origin another_branch
From gitlab.my-inc.com:projname/proj
* branch another_branch -> FETCH_HEAD
并且仍然得到:
git branch --set-upstream-to origin/another_branch
error: the requested upstream branch 'origin/another_branch' does not exist
hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.
现在我觉得完全不是人类看到其他人在他们的git上玩得很好......
所以请帮忙,并提前致谢。
Want to download another remote branch to make maintenace, then push back.
so I tried:
git switch another_branch
fatal: invalid reference: another_branch
tried:
git checkout --track origin/another_branch
fatal: 'origin/another_branch' is not a commit and a branch 'another_branch' cannot be created from it
tried:
git checkout another_branch
error: pathspec 'another_branch' did not match any file(s) known to git
tried:
git fetch origin another_branch:another_branch
From gitlab.my-inc.com:projname/proj
* [new branch] another_branch -> another_branch
git checkout another_branch
Switched to branch 'another_branch'
seems good but:
git pull
fatal: refusing to merge unrelated histories
git branch -vv
* another_branch 421f45e normal commit comments
git branch --set-upstream-to origin/another_branch
error: the requested upstream branch 'origin/another_branch' does not exist
hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.
so, I tried:
git fetch
git fetch origin another_branch
From gitlab.my-inc.com:projname/proj
* branch another_branch -> FETCH_HEAD
and still got:
git branch --set-upstream-to origin/another_branch
error: the requested upstream branch 'origin/another_branch' does not exist
hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.
Now I feel totally not human seeing others playing well with their git...
So please help, and thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要 gitbranch -avv 不列出origin/another_branch,简单的 git switch another_branch 就不起作用。
它的 猜测模式 将使命令为:
根据您的情况,请检查遥控器的refspec
或者,正如 torek 在 comments,在多值的情况下:
它应该像
这意味着它应该获取所有分支,而不是仅获取一个分支,例如:
如果它不获取所有分支,使用该 refspec (
+refs/heads/*:refs/remotes/origin/*
) 进行设置,git fetch
将能够向您显示远程存储库,希望包括,起源/another_branch
As long as
git branch -avv
does not listorigin/another_branch
, a simplegit switch another_branch
will not work.Its guess mode would make that command as:
In your case, check the refspec of your remote
Or, as torek suggests in the comments, in case of multi-values:
It should be like
Which means it should fetch all branches, instead of fetching only one branch, for instance:
If it does not fetch all branches, set it using that refspec (
+refs/heads/*:refs/remotes/origin/*
), and agit fetch
will be able to show you remote branches of the remote repository, including, hopefully,origin/another_branch