What have you found for these years?

2010-04-09

checkout and track all remote branches

I always want to track all remote branches,
not manually invoking this:

  $ git checkout -b whatever --track github/whatever

This is tedious and annoying if you need to develop
on many branches other people are working on.
There's a bash script doing this, here it is:

  http://stackoverflow.com/questions/379081/

But I just hope this could be built into git,
not separated as a standalone script. (or function)
So I've written a git alias so stupid and ugly...
usage is as following:

  $ git sync

It would checkout and track all remote branches with the same
name if the name isn't existed as a local branch already,
if the name is already existed, it would fail silently.
To redo this, delete the old branch first:

  $ git branch -d whatever

If git is complaining, just follow its instruction if that's your
intention, and git sync again. Here the alias is:

[alias]
  sync = !git branch -r | egrep '^[^>]+$' | sed -E 's/(.*?)\\/(.*?)/git branch \\2 --track\\1\\/\\2/' | ruby -e 'puts $stdin.read.split(\"\n\").map{ |s| send(:`, s) }.reject(&:empty?)' 2> /dev/null

Just put it into `~/.gitconfig` and you're done.
Cleaner implementation wanted! The problem is...
There are too many level of quotes, so I end up
using `ruby', instead of `xargs'. I can't even use
string interpolation like #{something} because of
the # character... Shell programming is really frustrating.

The full `~/.gitconfig` file I used can be found here:

  http://github.com/godfat/dot-rc/blob/master/.gitconfig

0 retries:

Post a Comment

Note: Only a member of this blog may post a comment.



All texts are licensed under CC Attribution 3.0