git 中的 fetch 没有得到所有的分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11623862/
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
fetch in git doesn't get all branches
提问by Edward Newell
I have cloned a repository, after which somebody else has created a new branch, which I'd like to start working on. I read the manual, and it seems dead straight easy. Strangely it's not working, and all the posts I've found suggest I'm doing the right thing. So I'll subject myself to the lambasting, because there mustbe something obviously wrong with this:
我克隆了一个存储库,之后其他人创建了一个新分支,我想开始处理它。我阅读了手册,看起来很简单。奇怪的是它不起作用,我发现的所有帖子都表明我在做正确的事情。所以我会受到谴责,因为这肯定有明显的错误:
The correct action seemsto be
正确的动作似乎是
git fetch
git branch -a
* master
remotes/origin/HEAD --> origin/master
remotes/origin/master
git checkout -b dev-gml origin/dev-gml
At this point there is a problem, for some reason after git fetch
I can't see the dev-gml remote branch. Why not? If I clone the repository freshly, it's there, so certainly the remote branch exists:
此时出现问题,git fetch
不知什么原因后我看不到dev-gml远程分支。为什么不?如果我重新克隆存储库,它就在那里,所以肯定存在远程分支:
$ mkdir ../gitest
$ cd ../gitest
$ git clone https://github.com/example/proj.git
Cloning into proj...
remote: Counting objects: 1155, done.
remote: Compressing objects: 100% (383/383), done.
remote: Total 1155 (delta 741), reused 1155 (delta 741)
Receiving objects: 100% (1155/1155), 477.22 KiB | 877 KiB/s, done.
Resolving deltas: 100% (741/741), done.
$ cd projdir
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/dev-gml
remotes/origin/master
I've tried git update
, git pull
, git fetch --all
, git pretty-please
in all possible permutations...
我已经尝试过git update
, git pull
, git fetch --all
,git pretty-please
在所有可能的排列中......
回答by AndASM
The problem can be seen when checking the remote.origin.fetch
setting
(The lines starting with $
are bash prompts with the commands I typed. The other lines are the resulting output)
检查remote.origin.fetch
设置时可以看到问题
($
以我输入的命令开头的行是bash提示。其他行是结果输出)
$ git config --get remote.origin.fetch
+refs/heads/master:refs/remotes/origin/master
As you can see, in my case, the remote was set to fetch the master branch specifically and only. I fixed it as per below, including the second command to check the results.
如您所见,就我而言,远程设置为专门且仅获取主分支。我按照下面的方法修复了它,包括检查结果的第二个命令。
$ git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
$ git config --get remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*
The wildcard *
of course means everything under that path.
通配符*
当然意味着该路径下的所有内容。
Unfortunately I saw this commentafter I had already dug through and found the answer by trial and error.
不幸的是,在我已经深入挖掘并通过反复试验找到答案之后,我看到了这条评论。
回答by stux
I had this issue today on a repo.
我今天在 repo 上遇到了这个问题。
It wasn't the +refs/heads/*:refs/remotes/origin/*
issue as per top solution.
这不是+refs/heads/*:refs/remotes/origin/*
顶级解决方案的问题。
Symptom was simply that git fetch origin
or git fetch
just didn't appear to do anything, although there were remote branches to fetch.
症状很简单,git fetch origin
或者git fetch
只是似乎没有做任何事情,尽管有远程分支要获取。
After trying lots of things, I removed the origin remote, and recreated it. That seems to have fixed it. Don't know why.
在尝试了很多事情之后,我删除了原始遥控器,并重新创建了它。这似乎已经解决了它。不知道为什么。
remove with:
git remote rm origin
删除:
git remote rm origin
and recreate with:
git remote add origin <git uri>
并重新创建:
git remote add origin <git uri>
回答by philipvr
Remote update
远程更新
You need to run
你需要跑
git remote update
or
或者
git remote update <remote>
Then you can run git branch -r
to list the remote branches.
然后您可以运行git branch -r
以列出远程分支。
Checkout a new branch
签出一个新的分支
To track a (new) remote branch as a local branch:
将(新的)远程分支作为本地分支进行跟踪:
git checkout -b <local branch> <remote>/<remote branch>
or (sometimes it doesn't work without the extra remotes/
):
或(有时它没有额外的工作remotes/
):
git checkout -b <local branch> remotes/<remote>/<remote branch>
Helpful git cheatsheets
有用的 git 备忘单
- Git Cheat Sheet(My personal favorite)
- Some notes on git
- Git Cheat Sheet(pdf)
- Git 备忘单(我个人最喜欢的)
- 一些关于 git 的笔记
- Git 备忘单(pdf)
回答by Samet ?ZTOPRAK
write it from the terminal
从终端写入
git fetch --prune.
it works fine.
它工作正常。
回答by Swapna
To make it more specific Create a tracking branch, which means you are now tracking a remote branch.
为了使它更具体 创建一个跟踪分支,这意味着您现在正在跟踪一个远程分支。
git branch --track branch remote-branch
git branch --track exp remotes/origin/experimental
After which you can
之后你可以
git branch # to see the remote tracking branch "exp" created .
Then to work on that branch do
然后在那个分支上工作
git checkout branchname
git checkout exp
After you have made changes to the branch. You can git fetch and git merge with your remote tracking branch to merge your changes and push to the remote branch as below.
对分支进行更改后。您可以 git fetch 和 git merge 与您的远程跟踪分支合并您的更改并推送到远程分支,如下所示。
git fetch origin
git merge origin/experimental
git push origin/experimental
Hope it helps and gives you an idea, how this works.
希望它对您有所帮助并为您提供一个想法,这是如何工作的。
回答by Juh_
I had a similar problem, however in my case I could pull/push to the remote branch but git status
didn't show the local branch state w.r.t the remote ones.
我有一个类似的问题,但是在我的情况下,我可以拉/推到远程分支,但git status
没有显示远程分支的本地分支状态。
Also, in my case git config --get remote.origin.fetch
didn't return anything
另外,在我的情况下git config --get remote.origin.fetch
没有返回任何东西
The problem is that there was a typo in the .git/config
file in the fetch line of the respective remote block. Probably something I added by mistake previously (sometimes I directly look at this file, or even edit it)
问题是.git/config
相应远程块的提取行中的文件中存在拼写错误。可能是我之前错误添加的东西(有时我直接看这个文件,甚至编辑它)
So, check if your remote entry in the .git/config
file is correct, e.g.:
因此,请检查.git/config
文件中的远程条目是否正确,例如:
[remote "origin"]
url = https://[server]/[user or organization]/[repo].git
fetch = +refs/heads/*:refs/remotes/origin/*
回答by Lukas Lukac
Had the same problem today setting up my repo from scratch. I tried everything, nothing worked except removing the origin and re-adding it back again.
今天从头开始设置我的回购时遇到了同样的问题。我尝试了一切,除了删除原点并再次重新添加之外,没有任何效果。
git remote rm origin
git remote add origin [email protected]:web3coach/the-blockchain-bar-newsletter-edition.git
git fetch --all
// Ta daaa all branches fetched
回答by jerseyboy
This could be due to a face palm moment: if you switch between several clones it is easy to find yourself in the wrong source tree trying to pull a non-existent branch. It is easier when the clones have similar names, or the repos are distinct clones for the same project from each of multiple contributors. A new git clone would obviously seem to solve that "problem" when the real problem is losing focus or working context or both.
这可能是由于面部手掌时刻:如果您在多个克隆之间切换,很容易发现自己在错误的源树中试图拉出不存在的分支。如果克隆具有相似的名称,或者存储库是来自多个贡献者中的每一个的同一项目的不同克隆,则更容易。当真正的问题是失去焦点或工作环境或两者兼而有之时,新的 git clone 显然似乎可以解决该“问题”。
回答by Maslow
I had to go into my GitExtensions Remote Repositories as nothing here seemed to be working. There I saw that 2 branches had no remote repository configured. after adjusting it looks as follows
我不得不进入我的 GitExtensions 远程存储库,因为这里似乎没有任何工作。在那里我看到 2 个分支没有配置远程存储库。调整后如下图
Notice branch noExternal3
still shows as not having a remote repository. Not sure what combo of bash commands would have found or adjusted that.
注意分支noExternal3
仍然显示为没有远程存储库。不确定什么 bash 命令组合会找到或调整它。
回答by chazefate
We had the same problem and you have to use
我们有同样的问题,你必须使用
git fetch
git push origin branch_name
git branch -r
Hope this help someone facing the same problem
希望这可以帮助面临同样问题的人