# [usability bug] git branch -a does not disambiguate remote and local branches

6 messages from 2008-12-15 to 2008-12-16. Participants: Constantine Plotnikov, Johannes Schindelin, Lars Hjemli, Boyd Stephen Smith Jr., Björn Steinbrink.
Thread: https://gitlist.dev/t/16741

## Constantine Plotnikov, 2008-12-15 18:15

Subject: [usability bug] git branch -a does not disambiguate remote and local branches
Message-ID: <85647ef50812151015t4d5bc2b8p4ea53a0e4ad25e64@mail.gmail.com>
URL: https://gitlist.dev/e/85647ef50812151015t4d5bc2b8p4ea53a0e4ad25e64%40mail.gmail.com

```
Let's consider the following scenario:

mkdir bare.git
mkdir local
cd bare.git
git --bare init
cd ../local
git init
echo test > test.txt
git add test.txt
git commit -m test
git remote add origin `pwd`/../bare.git
git push --all
git checkout -b origin/master master
echo updated > test.txt
git add test.txt
git commit -m updated

Note that that in this scenario, the user has created local branch in
the folder with the same name as a remote branch. While the supposed
user here is apparently shooting itself in the foot, the scenario is
still supported by git, and might happen as a result of more logical
git operations (like git fetch).

After this scenario is executed, git branch -a will give the following output:
  master
* origin/master
  origin/master

Note that there is two origin/master entries, but it is not clear
which is remote is and which is the local. I think that "git branch
-a" should print unambiguous names, qualifying them if needed.

Constantine

```

## Johannes Schindelin, 2008-12-15 19:09

Subject: Re: [usability bug] git branch -a does not disambiguate remote and local branches
Message-ID: <alpine.DEB.1.00.0812152005490.30769@pacific.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0812152005490.30769%40pacific.mpi-cbg.de
In-Reply-To: <85647ef50812151015t4d5bc2b8p4ea53a0e4ad25e64@mail.gmail.com>

```
Hi,

On Mon, 15 Dec 2008, Constantine Plotnikov wrote:

> Let's consider the following scenario:
> 
> mkdir bare.git
> mkdir local
> cd bare.git
> git --bare init
> cd ../local
> git init
> echo test > test.txt
> git add test.txt
> git commit -m test
> git remote add origin `pwd`/../bare.git
> git push --all
> git checkout -b origin/master master
> echo updated > test.txt
> git add test.txt
> git commit -m updated
> 
> Note that that in this scenario, the user has created local branch in
> the folder with the same name as a remote branch. While the supposed
> user here is apparently shooting itself in the foot, the scenario is
> still supported by git, and might happen as a result of more logical
> git operations (like git fetch).

It is only half-supported, and Git will complain, saying that there are 
ambiguous branches.

IMHO it is better to be nice to the many users who do not try to shoot 
themselves in the foot, by showing them the nice short names that will 
work.

The others are warned when they use the ambiguous short names anyway.

Ciao,
Dscho

```

## Constantine Plotnikov, 2008-12-15 19:15

Subject: Re: [usability bug] git branch -a does not disambiguate remote and local branches
Message-ID: <85647ef50812151115k41451d84jcfbdd9a187813e00@mail.gmail.com>
URL: https://gitlist.dev/e/85647ef50812151115k41451d84jcfbdd9a187813e00%40mail.gmail.com
In-Reply-To: <alpine.DEB.1.00.0812152005490.30769@pacific.mpi-cbg.de>

```
On Mon, Dec 15, 2008 at 10:09 PM, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
> Hi,
>
> On Mon, 15 Dec 2008, Constantine Plotnikov wrote:
>
>> Let's consider the following scenario:
>>
>> mkdir bare.git
>> mkdir local
>> cd bare.git
>> git --bare init
>> cd ../local
>> git init
>> echo test > test.txt
>> git add test.txt
>> git commit -m test
>> git remote add origin `pwd`/../bare.git
>> git push --all
>> git checkout -b origin/master master
>> echo updated > test.txt
>> git add test.txt
>> git commit -m updated
>>
>> Note that that in this scenario, the user has created local branch in
>> the folder with the same name as a remote branch. While the supposed
>> user here is apparently shooting itself in the foot, the scenario is
>> still supported by git, and might happen as a result of more logical
>> git operations (like git fetch).
>
> It is only half-supported, and Git will complain, saying that there are
> ambiguous branches.
>
> IMHO it is better to be nice to the many users who do not try to shoot
> themselves in the foot, by showing them the nice short names that will
> work.
>
> The others are warned when they use the ambiguous short names anyway.
>
It is possible to be nice to to both categories showing shortest
disambiguated output like:

  master
* heads/origin/master
  remotes/origin/master

Constantine

```

## Boyd Stephen Smith Jr., 2008-12-15 19:21

Subject: Re: [usability bug] git branch -a does not disambiguate remote and local branches
Message-ID: <200812151321.05421.bss03@volumehost.net>
URL: https://gitlist.dev/e/200812151321.05421.bss03%40volumehost.net
In-Reply-To: <alpine.DEB.1.00.0812152005490.30769@pacific.mpi-cbg.de>

```
On Monday 2008 December 15 13:09:16 Johannes Schindelin wrote:
>IMHO it is better to be nice to the many users who do not try to shoot
>themselves in the foot, by showing them the nice short names that will
>work.

It should be possible to support both.  Short names when they are unique, 
longer names when the short names are ambiguous.
-- 
Boyd Stephen Smith Jr.                     ,= ,-_-. =. 
bss03@volumehost.net                      ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy           `-'(. .)`-' 
http://iguanasuicide.org/                      \_/     

```

## Lars Hjemli, 2008-12-15 19:24

Subject: Re: [usability bug] git branch -a does not disambiguate remote and local branches
Message-ID: <8c5c35580812151124h5f9b8704l492a5a9a7eb48d1a@mail.gmail.com>
URL: https://gitlist.dev/e/8c5c35580812151124h5f9b8704l492a5a9a7eb48d1a%40mail.gmail.com
In-Reply-To: <85647ef50812151015t4d5bc2b8p4ea53a0e4ad25e64@mail.gmail.com>

```
On Mon, Dec 15, 2008 at 19:15, Constantine Plotnikov
<constantine.plotnikov@gmail.com> wrote:
> After this scenario is executed, git branch -a will give the following output:
>  master
> * origin/master
>  origin/master
>
> Note that there is two origin/master entries, but it is not clear
> which is remote is and which is the local.

You can use `git branch -a --color` to see the difference (issue `git
config --global color.branch true` to use --color automatically).

--
larsh

```

## Björn Steinbrink, 2008-12-16 06:26

Subject: Re: [usability bug] git branch -a does not disambiguate remote and local branches
Message-ID: <20081216062634.GB3684@atjola.homenet>
URL: https://gitlist.dev/e/20081216062634.GB3684%40atjola.homenet
In-Reply-To: <85647ef50812151015t4d5bc2b8p4ea53a0e4ad25e64@mail.gmail.com>

```
On 2008.12.15 21:15:15 +0300, Constantine Plotnikov wrote:
> After this scenario is executed, git branch -a will give the following output:
>   master
> * origin/master
>   origin/master
> 
> Note that there is two origin/master entries, but it is not clear
> which is remote is and which is the local. I think that "git branch
> -a" should print unambiguous names, qualifying them if needed.

Actually, it is clear. The one with the * is the local one. The remote
tracking branch will never be marked as checked out, as you would get a
detached HEAD when you do "git checkout remotes/origin/master".

When there are duplicate entries, you can be sure that you have a local
branch head and a remote tracking branch with the same shortname. And
when one of them has been marked as checked out, you can be sure that it
is the local one.

Björn

```
