远程分支没有出现在“git branch -r”中

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

Remote branch is not showing up in "git branch -r"

git

提问by feargal

I have been pushing to a remote Bitbucket repository and recently a colleague has pushed a new branch he created to the same repository.

我一直在推送到远程 Bitbucket 存储库,最近一位同事将他创建的新分支推送到同一个存储库。

I'm trying to fetch the changes he uploaded.

我正在尝试获取他上传的更改。

 $ git branch -a
 * master
 localbranch1
 localbranch2
 remotes/origin/master

$ git branch -r origin/master

$ git branch -r origin/master

In the web UI for Bitbucket I can see the branch he has made. How can I do this?

在 Bitbucket 的 Web UI 中,我可以看到他创建的分支。我怎样才能做到这一点?

Next try:

下一次尝试:

$ git fetch bitbucket
Password for 'https://[email protected]':
From https://bitbucket.org/user/repo
 * branch            HEAD       -> FETCH_HEAD

If the branch he created is called new_branch_bshould I be expecting to see the following?

如果他创建的分支名为new_branch_b,我应该期待看到以下内容吗?

$ git branch -r
origin/master
origin/new_branch_b

Third try:

第三次尝试:

$ git remote update
Fetching bitbucket
Password for 'https://[email protected]':
From https://bitbucket.org/user/repo
 * branch            HEAD       -> FETCH_HEAD

$ git branch -r
  origin/master

Fourth try:

第四次尝试:

[remote "bitbucket"]
url = https://[email protected]/user/repo.git

I called the remote bitbucketrather than origin (at least that's what I recall; I set it up a while ago)

我打电话给遥控器bitbucket而不是原点(至少我记得是这样;我不久前设置了它)

Fifth try:

第五次尝试:

I updated the Bitbucket remote configuration as per kan's answer:

我根据kan 的回答更新了 Bitbucket 远程配置:

$ git config -e

$ git 配置 -e

[remote "bitbucket"]
    url = https://[email protected]/user/repo.git
    fetch = +refs/heads/*:refs/remotes/bitbucket/*

For most people it will be called origin:

对于大多数人来说,它会被称为起源:

[remote "origin"]
    url = https://[email protected]/user/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

Afterwards,

然后,

$ git remote update

Fetching bitbucket
Password for 'https://[email protected]':
remote: Counting objects: 48, done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 35 (delta 21), reused 0 (delta 0)
Unpacking objects: 100% (35/35), done.
From https://bitbucket.org/user/repo
 * [new branch]      branch_name1 -> origin/branch_name1
 * [new branch]      branch_name2    -> origin/branch_name2

.... and so on.

.... 等等。

I think git fetch originwould also work for git remote update.

我认为git fetch origin也适用于git remote update.

采纳答案by kan

The remotesection also specifies fetch rules. You could add something like this into it to fetch all branches from the remote:

remote部分还指定了获取规则。您可以在其中添加类似的内容以从远程获取所有分支:

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

(Or replace originwith bitbucket.)

(或替换originbitbucket。)

Please read about it here: 10.5 Git Internals - The Refspec

请在此处阅读:10.5 Git Internals - The Refspec

回答by Bruno

Update your remote if you still haven't done so:

如果您还没有这样做,请更新您的遥控器:

$ git remote update
$ git branch -r

回答by DonPaulie

If you clone with the --depthparameter, it sets .git/confignot to fetch all branches, but only master.

如果使用--depth参数进行克隆,则它设置为.git/config不获取所有分支,而只获取主分支。

You can simply omit the parameter or update the configuration file from

您可以简单地省略参数或更新配置文件

fetch = +refs/heads/master:refs/remotes/origin/master

to

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

回答by jessicah

I had the same issue. It seems the easiest solution is to just remove the remote, readd it, and fetch.

我遇到过同样的问题。似乎最简单的解决方案是删除遥控器,读取它并获取。

回答by Thushan

Unfortunately, git branch -aand git branch -rdo notshow you all remote branches, if you haven't executed a "git fetch".

不幸的是,git branch -agit branch -r告诉你所有的远程分支机构,如果你还没有执行的“混帐提取”。

git remote show originworks consistently all the time. Also git show-refshows all references in the Git repository. However, it works just like the git branchcommand.

git remote show origin始终如一地工作。还git show-ref显示 Git 存储库中的所有引用。但是,它就像git branch命令一样工作。