Git tracking

We’ve been switching to git recently and something mildly annoys me about it not to mention certain colleagues of mine have a dread fear of editing configuration files. In most git tutorials I’ve seen, once you have created your git project and then want to set up tracking of your master branch against a remote server you are required to edit config files. Git has so many nice little tools for doing everything else, why not something for this? So, for swift justice, we decided to remedy the situation with some bash-fu.


function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}

function git-track {
  CURRENT_BRANCH=$(parse_git_branch)
  git-config branch.$CURRENT_BRANCH.remote $1
  git-config branch.$CURRENT_BRANCH.merge refs/heads/$CURRENT_BRANCH
}

With the above snippet in your bash conf (yes, I recognise the irony of editing a config file to give you a command to avoid editing a config file) you can just type:


git-track [remote name]

to track the branch you are currently in against the same branch in that remote. Simple.

Found this interesting? Share it:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Furl
  • Ma.gnolia
  • NewsVine
  • Reddit
  • TwitThis

Comments

  1. Nice script, this has been a pain point for me in the past too!

Trackbacks / Pings

  1. Trackback URl →
  2. Git - setting up a remote repository and doing an initial ‘push’ — The Lucid January 06 2010 at 05:15 PM

Leave a Reply