# Best way to specify all local branches and all remote branches.

6 messages from 2008-02-11 to 2008-02-11. Participants: Paul Gardiner, Jakub Narebski, Johannes Schindelin.
Thread: https://gitlist.dev/t/12041

## Paul Gardiner, 2008-02-11 18:51

Subject: Best way to specify all local branches and all remote branches.
Message-ID: <47B09921.2070109@glidos.net>
URL: https://gitlist.dev/e/47B09921.2070109%40glidos.net

```
New to git, and often finding it hard to specify the correct
refs for a command. Here's an example where I was converting
all the files in all the commits from unix line endings to
DOS line endings. You can see I've ended up using cd and ls.
I'm sure there must be a better way.

$ cd /home/public/tmp/git/
$ yes |rm -r vdos32
$ git clone /export/git/vdos32.git vdos32
$ cd vdos32/
$ for f in `(cd /export/git/vdos32.git/refs/heads; ls)|sed -e
    '/master/d' -e '/origin/d'`; do git fetch origin $f:$f; done
$ git-filter-branch --tag-name-filter cat --tree-filter 'find . -type f
    ! -name \*.gif ! -name \*.ico|xargs unix2dos -q' `(cd
    .git/refs/heads;ls)`



With git-filter-branch, I'm surprised I can't use --all.
The docs suggest that A --not B is permitted. I've
also seen refs/heads/* used in the docs but never
managed to get it to work. Most greatful for any
advice.

P.

```

## Jakub Narebski, 2008-02-11 19:10

Subject: Re: Best way to specify all local branches and all remote branches.
Message-ID: <m3ir0ve2c1.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m3ir0ve2c1.fsf%40localhost.localdomain
In-Reply-To: <47B09921.2070109@glidos.net>

```
Paul Gardiner <osronline@glidos.net> writes:

> New to git, and often finding it hard to specify the correct
> refs for a command. Here's an example where I was converting
> all the files in all the commits from unix line endings to
> DOS line endings. You can see I've ended up using cd and ls.
> I'm sure there must be a better way.

git-for-each-ref, git-show-ref, git-ls-remote / git-peek-remote.
 
> $ cd /home/public/tmp/git/
> $ yes |rm -r vdos32
> $ git clone /export/git/vdos32.git vdos32
> $ cd vdos32/
> $ for f in `(cd /export/git/vdos32.git/refs/heads; ls)|sed -e
>     '/master/d' -e '/origin/d'`; do git fetch origin $f:$f; done
> $ git-filter-branch --tag-name-filter cat --tree-filter 'find . -type f
>     ! -name \*.gif ! -name \*.ico|xargs unix2dos -q' `(cd
>     .git/refs/heads;ls)`

If you want to fetch all branches, you can specify globbing refspec;
of course if you use separate remotes layout, or mirror layout.

If you want to pass all branches to git command, usually --all would
be enough (sometimes --heads).
 
> With git-filter-branch, I'm surprised I can't use --all.

git-filter-branch is about single branch; I'm not sure if it should
support --all.

-- 
Jakub Narebski
Poland
ShadeHawk on #git

```

## Paul Gardiner, 2008-02-11 19:40

Subject: Re: Best way to specify all local branches and all remote branches.
Message-ID: <47B0A4B6.2090408@glidos.net>
URL: https://gitlist.dev/e/47B0A4B6.2090408%40glidos.net
In-Reply-To: <m3ir0ve2c1.fsf@localhost.localdomain>

```
Jakub Narebski wrote:
> Paul Gardiner <osronline@glidos.net> writes:
> 
>> New to git, and often finding it hard to specify the correct
>> refs for a command. Here's an example where I was converting
>> all the files in all the commits from unix line endings to
>> DOS line endings. You can see I've ended up using cd and ls.
>> I'm sure there must be a better way.
> 
> git-for-each-ref, git-show-ref, git-ls-remote / git-peek-remote.

Ah right, those look hellishly useful, thanks.

>> $ cd /home/public/tmp/git/
>> $ yes |rm -r vdos32
>> $ git clone /export/git/vdos32.git vdos32
>> $ cd vdos32/
>> $ for f in `(cd /export/git/vdos32.git/refs/heads; ls)|sed -e
>>     '/master/d' -e '/origin/d'`; do git fetch origin $f:$f; done
>> $ git-filter-branch --tag-name-filter cat --tree-filter 'find . -type f
>>     ! -name \*.gif ! -name \*.ico|xargs unix2dos -q' `(cd
>>     .git/refs/heads;ls)`
> 
> If you want to fetch all branches, you can specify globbing refspec;
> of course if you use separate remotes layout, or mirror layout.

I think I tried that with my line 5 above. I tried 
refs/heads/*:refs/heads/* as the ref spec. Should something like that
work?

> If you want to pass all branches to git command, usually --all would
> be enough (sometimes --heads).
>  
>> With git-filter-branch, I'm surprised I can't use --all.
> 
> git-filter-branch is about single branch; I'm not sure if it should
> support --all.

It seems to work with multiple branches, and I think it's important
that it does, because as far as I can tell, that's the only way
to filter a whole repository without visiting some commits more
than once. Certainly my command, using cd/ls, worked and visited
each commit exactly once.

Cheers,
	Paul.

```

## Johannes Schindelin, 2008-02-11 20:23

Subject: Re: Best way to specify all local branches and all remote branches.
Message-ID: <alpine.LSU.1.00.0802112022560.3870@racer.site>
URL: https://gitlist.dev/e/alpine.LSU.1.00.0802112022560.3870%40racer.site
In-Reply-To: <m3ir0ve2c1.fsf@localhost.localdomain>

```
Hi,

On Mon, 11 Feb 2008, Jakub Narebski wrote:

> git-filter-branch is about single branch;

No.

> I'm not sure if it should support --all.

It does.

Ciao,
Dscho

```

## Paul Gardiner, 2008-02-11 21:00

Subject: Re: Best way to specify all local branches and all remote branches.
Message-ID: <47B0B775.1050401@glidos.net>
URL: https://gitlist.dev/e/47B0B775.1050401%40glidos.net
In-Reply-To: <alpine.LSU.1.00.0802112022560.3870@racer.site>

```
Johannes Schindelin wrote:
> Hi,
> 
> On Mon, 11 Feb 2008, Jakub Narebski wrote:
> 
>> git-filter-branch is about single branch;
> 
> No.
> 
>> I'm not sure if it should support --all.
> 
> It does.

Yep, it does. I'd forgotten how to drive the shell. It works if
I put -- --all.

Turns out that isn't what I want though. I want just the local
branches. Still can't find a way to do it other than my cd/ls
thing.

```

## Jakub Narebski, 2008-02-11 21:34

Subject: Re: Best way to specify all local branches and all remote branches.
Message-ID: <m3abm7dvp1.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m3abm7dvp1.fsf%40localhost.localdomain
In-Reply-To: <47B0B775.1050401@glidos.net>

```
Paul Gardiner <osronline@glidos.net> writes:

> Johannes Schindelin wrote:
>> On Mon, 11 Feb 2008, Jakub Narebski wrote:
>>
>>> git-filter-branch [...] should support --all.
>>
>> It does.
> 
> Yep, it does. I'd forgotten how to drive the shell. It works if
> I put -- --all.
> 
> Turns out that isn't what I want though. I want just the local
> branches. Still can't find a way to do it other than my cd/ls
> thing.

I wrote: git-for-each-ref(1). See documentation, please.

  $(git for-each-ref --shell --format="%(refname)" "refs/heads/*")

-- 
Jakub Narebski
Poland
ShadeHawk on #git

```
