简体   繁体   中英

Comparing 'git branch' and 'git ls-remote' for bare repo clone of public repo, and non-bare repo clone of bare one

I cloned a public repository (in this case, Pressflow/Drupal) into a bare repository on our internal shared repo, then I cloned that one into a non-bare repository to be used on a developer machine. I'm a git newbie and trying to understand this stuff better, so I ran a few commands like 'git branch' and 'git ls-remote' on both repositories to see what's going on, and the following is the output. I'd appreciate if someone who knows this stuff could help explain to me why the output of those commands on one repository is different from the output on the other repository. First, here's what is seen on the developer non-bare (contains working copy) repository:

git branch

* master

git branch -a

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/rebuild

git ls-remote .

3403cde92193332e5a86c0ee1001652217f14b2c    HEAD
3403cde92193332e5a86c0ee1001652217f14b2c    refs/heads/master
70dc401eb10191f9c025e8e1883c3e281b52e066    refs/remotes/origin/HEAD
70dc401eb10191f9c025e8e1883c3e281b52e066    refs/remotes/origin/master
4c8d40b286c00c876bfcbcc31cd92aa32bb970fc    refs/remotes/origin/rebuild
78df712072ede26debe1a86609e92950643b554c    refs/tags/DRUPAL-6-10
8278623b80f3abac676992a656a1022d387d9543    refs/tags/DRUPAL-6-11
3b20e4b64adc53ca7d1687a7583665d6119dc0c5    refs/tags/DRUPAL-6-12
ee1b8b37951baa8b9894d8158d0f8524c649560f    refs/tags/DRUPAL-6-13
79567390f4107a1d069c5b225a7949689adeb84e    refs/tags/DRUPAL-6-14
1ac143798b92b6e9bc575a9e1c2feb118d986656    refs/tags/DRUPAL-6-15
96f8ffef3262136d090f6499b964f1aeadedf110    refs/tags/DRUPAL-6-16
af49a2dcd48d95957c13ec2b396f588b9ad3700c    refs/tags/DRUPAL-6-17
ed5cf3d5aa9d3bc7897a62c348fd30fd3a540f6e    refs/tags/DRUPAL-6-18
d72672c1c5b42d2a1f5bac83348265ef4702230a    refs/tags/DRUPAL-6-19
9b14a5b49ef0f775fa95daaf9be1cdf83e48f6e7    refs/tags/DRUPAL-6-20
b0a7d1b19d68b31db17702222977cf86503782a1    refs/tags/DRUPAL-6-21
51b583583e31bdcfceb6f43863dc456982b87b6c    refs/tags/DRUPAL-6-22
38a68987f1f77e1ebe2898ae612af4c75a3276aa    refs/tags/DRUPAL-6-6
829692b020d5227270d946744f63e693eada22ad    refs/tags/DRUPAL-6-7
146c7426f68c5bf45365d72285eb2badfa1e26dc    refs/tags/DRUPAL-6-8
b8ef169cbfa6a94ad63e039811a1c4429eb7628b    refs/tags/DRUPAL-6-9
b3b0f04b541b18b47819c65b3e63a242e0819e2a    refs/tags/pressflow-6.22.105

Now on the internal shared bare repository, if I run the same commands I get something different:

git branch

* master
  rebuild

git branch -a

* master
  rebuild

git ls-remote .

70dc401eb10191f9c025e8e1883c3e281b52e066    HEAD
70dc401eb10191f9c025e8e1883c3e281b52e066    refs/heads/master
4c8d40b286c00c876bfcbcc31cd92aa32bb970fc    refs/heads/rebuild
78df712072ede26debe1a86609e92950643b554c    refs/tags/DRUPAL-6-10
8278623b80f3abac676992a656a1022d387d9543    refs/tags/DRUPAL-6-11
3b20e4b64adc53ca7d1687a7583665d6119dc0c5    refs/tags/DRUPAL-6-12
ee1b8b37951baa8b9894d8158d0f8524c649560f    refs/tags/DRUPAL-6-13
79567390f4107a1d069c5b225a7949689adeb84e    refs/tags/DRUPAL-6-14
1ac143798b92b6e9bc575a9e1c2feb118d986656    refs/tags/DRUPAL-6-15
96f8ffef3262136d090f6499b964f1aeadedf110    refs/tags/DRUPAL-6-16
af49a2dcd48d95957c13ec2b396f588b9ad3700c    refs/tags/DRUPAL-6-17
ed5cf3d5aa9d3bc7897a62c348fd30fd3a540f6e    refs/tags/DRUPAL-6-18
d72672c1c5b42d2a1f5bac83348265ef4702230a    refs/tags/DRUPAL-6-19
9b14a5b49ef0f775fa95daaf9be1cdf83e48f6e7    refs/tags/DRUPAL-6-20
b0a7d1b19d68b31db17702222977cf86503782a1    refs/tags/DRUPAL-6-21
51b583583e31bdcfceb6f43863dc456982b87b6c    refs/tags/DRUPAL-6-22
38a68987f1f77e1ebe2898ae612af4c75a3276aa    refs/tags/DRUPAL-6-6
829692b020d5227270d946744f63e693eada22ad    refs/tags/DRUPAL-6-7
146c7426f68c5bf45365d72285eb2badfa1e26dc    refs/tags/DRUPAL-6-8
b8ef169cbfa6a94ad63e039811a1c4429eb7628b    refs/tags/DRUPAL-6-9
b3b0f04b541b18b47819c65b3e63a242e0819e2a    refs/tags/pressflow-6.22.105

Introduction

Simply put, even though the output you are seeing seems to be different it is in fact all telling you the same thing (albeit at different levels of verbosity).

What they are all saying is that the bare repo has 2 branches: master and rebuild For easy reference we'll call this the remote repo.The developer repo has one branch : master . We'll call this the local repo. Furthermore the local repo is tracking the remote repo and the remote repo is not tracking anything.

Explanation

git branch

local

First git branch on the local repo.

It just tells you that you have only one branch named master . The asterisk symbol * marks the branch you are currently on. (Which in this case can only be one master ).

If you run the same command with the -a flag it shows you both local and remote-tracking branches. You already know what * master is about.

The line remotes/origin/HEAD is a reference to the last commit in the currently checked out branch on the remote repo. Which in this case is on the master branch. This is roughly the same as what * marks for the local repo.

The next line remotes/origin/master tells you there is a branch named master on the remote named origin . The same applies to the next line in regards to the rebuild branch.

Now if you were to run git remote -v you would get some more information about which remotes are configured for your repo.

remote

On the remote repo (as we already know from the local branch) we can see it has two branches and is currently on the master branch. As it is not tracking any remote branches adding -a does not show anything new.

git ls-remote

This command list references in a repository. Dispite the remote part this can just as easily be a local repo (as you've already figured out by using . )

Branches, Remote-tracking branches, and Tags are all references (you can read more about these in the git book ).

local

The output of this command from your local repo tells you which commit the HEAD is at and the same information as what git branch -a gives you, only including commit hashes. Everything below that is references to tags.

remote

The output tells you more or less the same as what you see from the local repo, HEAD is the same revision as master and there are a bunch of tags. Only there's also a rebuild branch and (as there are no remotes), there's no entry for remotes.

In conslusion

I hope this clears matters up a bit. If things are unclear or I've missed anything, tell me in the comments and I'll update my answer to include it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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