Git:看不到新的远程分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12762922/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:43:37  来源:igfitidea点击:

Git: Cannot see new remote branch

gitremote-branch

提问by hybrid9

A colleague pushed a new remote branch to origin/dev/homepage and I cannot see it when I run:

同事推送了一个新的远程分支到origin/dev/homepage,运行时看不到:

$ git branch -r

I still see preexisting remote branches.

我仍然看到预先存在的远程分支。

I assume this is because my local remote refs are not up-to-date hence when I ran a git pull nothing happened since git pull only pulls on the current working branch correct? Unlike git push which pushes all branches that have changes to the corresponding remote branch?

我认为这是因为我的本地远程引用不是最新的,因此当我运行 git pull 时什么也没发生,因为 git pull 只在当前工作分支上正确拉动?不像 git push 将所有有更改的分支推送到相应的远程分支?

回答by Marco Leogrande

First, double check that the branch has been actually pushed remotely, by using the command git ls-remote origin. If the new branch appears in the output, try and give the command git fetch: it should download the branch references from the remote repository.

首先,使用命令仔细检查分支是否已实际远程推送git ls-remote origin。如果新分支出现在输出中,请尝试给出命令git fetch:它应该从远程存储库下载分支引用。

If your remote branch still does not appear, double check (in the ls-remoteoutput) what is the branch name on the remote and, specifically, if it begins with refs/heads/. This is because, by default, the value of remote.<name>.fetchis:

如果您的远程分支仍然没有出现,请仔细检查(在ls-remote输出中)远程分支的名称是什么,特别是它是否以refs/heads/. 这是因为,默认情况下,的值为remote.<name>.fetch

+refs/heads/*:refs/remotes/origin/*

so that only the remote references whose name starts with refs/heads/will be mapped locally as remote-tracking references under refs/remotes/origin/(i.e., they will become remote-tracking branches)

这样只有名称以 开头的远程引用refs/heads/才会在本地映射为远程跟踪引用refs/remotes/origin/(即,它们将成为远程跟踪分支)

回答by Jesse Glick

Check whether .git/configcontains

检查是否.git/config包含

[remote "origin"]
    url = …
    fetch = +refs/heads/master:refs/remotes/origin/master

If so, change it to say

如果是这样,请将其更改为

[remote "origin"]
    url = …
    fetch = +refs/heads/*:refs/remotes/origin/*

Then you should be able to use it:

然后你应该可以使用它:

$ git fetch
remote: Counting objects: …
remote: Compressing objects: ..
Unpacking objects: …
remote: …
From …
 * [new branch]            branchname -> origin/branchname
$ git checkout branchname
Branch branchname set up to track remote branch branchname from origin.
Switched to a new branch 'branchname'

回答by Jacek Dziurdzikowski

The simplest answer is:

最简单的答案是:

git fetch origin <branch_name>

git fetch origin <branch_name>

回答by metaforge

Doing a git remote updatewill also update the list of branches available from the remote repository.

执行git remote update还将更新远程存储库中可用的分支列表。

If you are using TortoiseGit, as of version 1.8.3.0, you can do "Git -> Sync" and there will be a "Remote Update" button in the lower left of the window that appears. Click that. Then you should be able to do "Git -> Switch/Checkout" and have the new remote branch appear in the dropdown of branches you can select.

如果您使用的是 TortoiseGit,从 1.8.3.0 版本开始,您可以执行“Git -> Sync”,然后在出现的窗口左下方会有一个“远程更新”按钮。单击那个。然后您应该能够执行“Git -> Switch/Checkout”,并让新的远程分支出现在您可以选择的分支下拉列表中。

回答by jpmottin

Let's say we are searching for release/1.0.5

假设我们正在寻找release/1.0.5

When git fetch -allis not workingand that you cannot see the remote branch and git branch -rnot show this specific branch.

如果git fetch -all不工作,并且您不能看到远程分支和git branch -r不显示这个特定分支。

1. Print all refs from remote (branches, tags, ...):

1. 从远程打印所有引用(分支,标签,...):

git ls-remote originShould show you remote branch you are searching for.

git ls-remote origin应该显示您正在搜索的远程分支。

e51c80fc0e03abeb2379327d85ceca3ca7bc3ee5        refs/heads/fix/PROJECT-352
179b545ac9dab49f85cecb5aca0d85cec8fb152d        refs/heads/fix/PROJECT-5
e850a29846ee1ecc9561f7717205c5f2d78a992b        refs/heads/master
ab4539faa42777bf98fb8785cec654f46f858d2a        refs/heads/release/1.0.5
dee135fb65685cec287c99b9d195d92441a60c2d        refs/heads/release/1.0.4
36e385cec9b639560d1d8b093034ed16a402c855        refs/heads/release/1.0
d80c1a52012985cec2f191a660341d8b7dd91deb        refs/tags/v1.0

The new branch 'release/1.0.5' appears in the output.

新分支 'release/1.0.5' 出现在输出中。

2. Force fetching a remote branch:

2. 强制获取远程分支:

git fetch origin <name_branch>:<name_branch>

git fetch origin <name_branch>:<name_branch>

$ git fetch origin release/1.0.5:release/1.0.5

remote: Enumerating objects: 385, done.
remote: Counting objects: 100% (313/313), done.
remote: Compressing objects: 100% (160/160), done.

Receiving objects: 100% (231/231), 21.02 KiB | 1.05 MiB/s, done.
Resolving deltas: 100% (98/98), completed with 42 local objects.
From http://git.repo:8080/projects/projectX
 * [new branch]        release/1.0.5 -> release/1.0.5

Now you have also the refs locally, you checkout (or whatever) this branch.

现在你也有本地的 refs,你结帐(或其他)这个分支。

Job done!

任务完成!

回答by BlackHatSamurai

It sounds trivial, but my issue was that I wasn't in the right project. Make sure you are in the project you expect to be in; otherwise, you won't be able to pull down the correct branches.

这听起来微不足道,但我的问题是我没有参与正确的项目。确保你在你希望参与的项目中;否则,您将无法拉下正确的分支。

回答by Rubber Duck

I used brute force and removed the remote and then added it

我使用了蛮力并移除了遥控器,然后添加了它

git remote rm <remote>
git remote add <url or ssh>

回答by Serj Sagan

What ended up finally working for me was to add the remote repository name to the git fetchcommand, like this:

最终对我有用的是将远程存储库名称添加到git fetch命令中,如下所示:

git fetch core

Now you can see all of them like this:

现在您可以像这样看到所有这些:

git branch --all

回答by thao vu

You can checkout remote branch /n git fetch && git checkout remotebranch

您可以结帐远程分支 /n git fetch && git checkout remotebranch