简体   繁体   English

git branch-全部不显示远程分支

[英]git branch --all not showing remote branch

I have a git repo for my dotfiles that I use like so 我有一个像这样使用的dotfile的git repo
100 ~$ git --git-dir=$HOME/.cfg/ --work-tree=$HOME [command] When I list my branches I would expect to see another branch * origin/master but it does not appear 100 ~$ git --git-dir=$HOME/.cfg/ --work-tree=$HOME [command]当列出我的分支时,我希望看到另一个分支* origin/master但它不会出现
101 ~$ git --git-dir=$HOME/.cfg/ --work-tree=$HOME branch --all * master In most other forum posts etc that I found, this was usually solved by adding the remote, but my remote has already been added. 101 ~$ git --git-dir=$HOME/.cfg/ --work-tree=$HOME branch --all * master在我发现的大多数其他论坛帖子中,这通常是通过添加遥控器来解决的,但是我的遥控器已经添加。 remote show origin confirms: remote show origin确认:
102 ~$ git --git-dir=$HOME/.cfg/ --work-tree=$HOME remote show origin * remote origin Fetch URL: git@bitbucket.org:myusername/dotfiles.git Push URL: git@bitbucket.org:myusername/dotfiles.git HEAD branch: master Local branch configured for 'git pull': master merges with remote master Local ref configured for 'git push': master pushes to master (up to date) Also, when I create commits I can push them to master on my remote with no issue. 102 ~$ git --git-dir=$HOME/.cfg/ --work-tree=$HOME remote show origin * remote origin Fetch URL: git@bitbucket.org:myusername/dotfiles.git Push URL: git@bitbucket.org:myusername/dotfiles.git HEAD branch: master Local branch configured for 'git pull': master merges with remote master Local ref configured for 'git push': master pushes to master (up to date)此外,当我创建提交时我可以毫无问题地将它们推送到我的遥控器上。 So what exactly is the origin/master branch, why is it seemingly automatically present on other local git repos I've worked with, and why is it not in this case? 那么origin/master分支到底是什么,为什么它似乎自动出现在我使用过的其他本地git仓库中,为什么在这种情况下却不存在呢?

Edit: I've included some more output from my terminal to clarify what isn't working 619 ~$ git --git-dir=$HOME/.cfg/ --work-tree=$HOME fetch origin From https://bitbucket.org/myusername/dotfiles * branch master -> FETCH_HEAD 620 ~$ git --git-dir=$HOME/.cfg/ --work-tree=$HOME push origin master Everything up-to-date 621 ~$ git --git-dir=$HOME/.cfg/ --work-tree=$HOME branch -a * master 622 ~$ git --git-dir=$HOME/.cfg/ --work-tree=$HOME branch -r 623 ~$ 编辑:我已经从终端中包含了更多输出,以阐明什么不起作用619 ~$ git --git-dir=$HOME/.cfg/ --work-tree=$HOME fetch origin From https://bitbucket.org/myusername/dotfiles * branch master -> FETCH_HEAD 620 ~$ git --git-dir=$HOME/.cfg/ --work-tree=$HOME push origin master Everything up-to-date 621 ~$ git --git-dir=$HOME/.cfg/ --work-tree=$HOME branch -a * master 622 ~$ git --git-dir=$HOME/.cfg/ --work-tree=$HOME branch -r 623 ~$

Most likely you just need to run: 您很可能只需要运行:

git fetch origin

(or even just git fetch ): call up Git on Bitbucket and have the Bitbucket Git talk with your Git, with them sending things to you. (或什至只是git fetch ):在Bitbucket上调用Git并让Bitbucket Git与您的Git对话,然后他们将事物发送给您。 Or you might need to run: 或者您可能需要运行:

git push origin master

which has your Git call up their Git and have a similar talk, in the "other direction". 让您的Git呼叫他们的Git并在“其他方向”进行类似的发言。 Your Git sends them any commits you have on your master that they don't, and then asks them—politely, "pretty please, if it's OK"—to set their master to the same commit that is the tip of your branch. 你的Git把它们发送您有任何关于提交你的master ,他们不这样做,然后问他们,礼貌,“拜托,如果它是确定”以诚自己设置master同一个commit,那就是你的分支的末端。

What's going on 这是怎么回事

Git terminology is confusing. Git术语令人困惑。 The name origin/master is not a branch name; 名称origin/master不是分支名称。 it's a remote-tracking branch name. 这是一个远程跟踪分支名称。 Just as the pair of words "branch name" is often shortened to "branch", the phrase remote-tracking branch name is often shortened to "remote-tracking branch". 就像将“分支名称”这对词通常缩写为“分支”一样,短语“ 远程跟踪分支名称”通常也被缩写为“远程跟踪分支”。 I have been experimenting with using "remote-tracking name" instead, because remote-tracking names aren't quite branches at all. 我一直在尝试使用“远程跟踪名称”代替,因为远程跟踪名称根本不是完全分支。 In particular, you can't get "on" a remote-tracking name the way you can get "on" a branch ... and while you can have your Git create remote-tracking names directly, you shouldn't. 特别是,您不能像在分支上那样“在”远程名称上“使用”……虽然您可以让Git直接创建远程跟踪的名称,但您不应该这样。

The purpose of these remote-tracking names is for your Git to remember what their Git said they had, the last time your Git talked with their Git. 这些远程跟踪名称的目的是为您的Git记住什么他们的Git说,他们的最后一次使用Git的交谈,他们的Git。 So you should have your Git call up their Git. 因此,您应该让您的Git呼叫他们的Git。 The two Gits can then talk, and yours can create, update, and even "prune" these remote-tracking things. 然后,两个Git可以交谈,而您的Git可以创建,更新甚至“修剪”这些远程跟踪的东西。

Running either of git fetch or git push has your Git call up another Git. 运行git fetchgit push使您的Git调用另一个Git。 To do so, your Git needs the URL of the other Git. 为此,您的Git需要另一个Git的URL。 Rather than making you type git@bitbucket.org:myusername/dotfiles.git all the time, your Git lets you use a short name like origin . 使用Git可以让您使用诸如origin的缩写,而不是一直输入git@bitbucket.org:myusername/dotfiles.git (You can choose or change the name; origin is just the default you get when you git clone by URL, as your clone origin -ated from the other Git.) (您可以选择或更改名称; origin只是通过URL进行git clone时获得的默认名称,因为您的克隆起源是从另一个Git开始的。)

This short name is a remote . 这个简称是一个遥控器 It's also used as the prefix for each of the remote-tracking names, because you can add more than one remote, and each Git at each URL has its own set of branches, so for your Git to remember the branches at, say, both origin and fred , you will want your Git to store one memory under origin/master and another under fred/master . 它也用作每个远程跟踪名称的前缀,因为您可以添加多个远程,并且每个 URL上的每个 Git都有自己的一组分支,因此您的Git可以记住两个分支上的分支originfred ,您将希望Git将一个内存存储在origin/master下,并将另一个存储在fred/master Of course if you only have one remote, this is overkill, but harmless. 当然,如果您只有一个遥控器,这是过大的,但无害。

Anyway, git fetch origin has them send you all of their branch names, and your Git then downloads any commits they have that you don't, and sets up your origin/* names to match their names. 无论如何, git fetch origin让他们向您发送所有分支名称,然后您的Git下载他们没有的所有提交,并设置您的origin/*名称以匹配其名称。 Similarly, git push origin <name> has your Git send them commits you have that they don't—new ones you made—and then asks them to set their <name> to the same as your <name> . 同样, git push origin <name>让您的Git向他们发送您没有的提交(您所做的新提交),然后要求他们将其<name>设置为与您的<name>相同。 Note that there's no funky renaming here: you ask them to set their master , not their jason/master . 请注意,这里没有时髦的重命名:您要求他们设置自己的master而不是jason/master So push is not quite the exact opposite of fetch, it's just as near as Git gets to the opposite. 因此,push并非与fetch完全相反,它与Git恰恰相反。

A side note on git pull 关于git pull附注

What about git pull ? git pull呢? Shouldn't pull be the opposite of push ? pull不应该与push相反吗?

Well, not quite: pull was there first, but it turns out to do too much and/or the wrong thing sometimes. 嗯,还不完全是:首先出现了拉动,但事实证明做得太多和/或有时做错了事。 So it got split into fetch followed by either rebase or merge . 因此,它分成了fetch然后进行了rebasemerge After you git fetch , you often—but not always—will want to integrate whatever you got from another Git into your own branches. git fetch ,您经常但不总是希望将从另一个Git获得的任何内容集成到自己的分支中。 At this point you will need a second Git command. 此时,您将需要第二个Git命令。 Using git pull will run both commands for you. 使用git pull将为您运行两个命令。 That's essentially all it does, and you can do that, but until you're familiar with how each of the various individual commands works—and more importantly, how they fail sometimes, and what to do about it—I find it's better to stick with the underlying commands. 这基本上就是它的全部工作,并且您可以做到,但是直到您熟悉各个命令的工作原理,更重要的是,它们有时会失败以及如何处理,我发现坚持下去是更好的选择与基本命令。 Otherwise, git pull may have one of the two commands fail, and then you won't know which command failed, much less what to do about it. 否则, git pull可能会使两个命令之一失败,然后您将不知道哪个命令失败,而要执行的操作则少得多。

The fix, as torek pointed out in a reply to his answer, was to set remote.origin.fetch. 正如torek在答复中指出的,解决方法是设置remote.origin.fetch。 I ran [git] config --edit and changed the relevant section from 我运行[git] config --edit并从

...
[remote "origin"]
    url = https://myusername@bitbucket.org/myusername/dotfiles.git
[status]
...

to

...
[remote "origin"]
    url = https://myusername@bitbucket.org/myusername/dotfiles.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[status]
...

After this, running [git] status informed me that 此后,运行[git] status通知我
On branch master Your branch is based on 'origin/master', but the upstream is gone. 在分支主服务器上您的分支基于“来源/主服务器”,但上游已消失。

Then after running [git] push I finally see the remote when I run [git] status and [git] branch -r 然后在运行[git] push之后,当我运行[git] status[git] branch -r时,我终于看到了遥控器

* For simplicity's sake, where I actually ran git --git-dir=$HOME/.cfg/ --work-tree=$HOME in my repo, I shortened it to [git] in the text above. *为了简单起见,在我的git --git-dir=$HOME/.cfg/ --work-tree=$HOME实际运行git --git-dir=$HOME/.cfg/ --work-tree=$HOME ,我在上面的文本中将其简化为[git]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM