Show Your GIT Branch Name In Your Prompt

Typing git branch over and over to see what branch you are on sucks. Sure, you could argue that you should always KNOW what branch you're currently working on. And if you did, you would obviously not be a git user.

Bouncing around branches can be pretty common, and I know I've messed some things up pretty bad not knowing what branch I was on.

So set up your shell to always put the name of the current branch into your prompt.

function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
 
function proml {
  local        BLUE="\[\033[0;34m\]"
  local         RED="\[\033[0;31m\]"
  local   LIGHT_RED="\[\033[1;31m\]"
  local       GREEN="\[\033[0;32m\]"
  local LIGHT_GREEN="\[\033[1;32m\]"
  local       WHITE="\[\033[1;37m\]"
  local  LIGHT_GRAY="\[\033[0;37m\]"
  case $TERM in
    xterm*)
    TITLEBAR='\[\033]0;\u@\h:\w\007\]'
    ;;
    *)
    TITLEBAR=""
    ;;
  esac
 
PS1="${TITLEBAR}\
$BLUE[$RED\$(date +%H:%M)$BLUE]\
$BLUE[$RED\u@\h:\w$GREEN\$(parse_git_branch)$BLUE]\
$GREEN\$ "
PS2='> '
PS4='+ '
}
proml

Pastie Link

Put this at the top of your .bash_profile and you'll be pimping your branch all over.

Thanks to @defunkt for this.

Popularity: 25% [?]

    Categories: GIT, Snippets     4 Comments »

GIT Intro Tonight @ CVREG

I will be giving a talk on GIT at tonights CVREG meeting.

If you've been reading about GIT lately and haven't had time to get your feet wet, come by to learn a little and see how it works. I'll be going over the benefits of GIT as well as doing some live demos to show how nice its silky smooth features work.

More info on the upcoming page

Popularity: 21% [?]

    Categories: CVREG, GIT, Ruby, Talks     No Comments »

Cleanly Migrate Your Subversion Repository To a GIT Repository

So you're ready to ride the GIT train eh? But what about all those projects in your subversion repository? Sure you could just use git-svn but what you really want is to cleanly move that repository and all its history to a nice new GIT repository.

Luckily it's not that hard. For this example I'm going to use my_blog as the application name you're porting to a GIT repository. We're basically going to just initialize a new GIT repository, point it at your SVN repository, and suck in your code and history while remapping the users to GIT users. We'll then just clone THAT repository to have a clean GIT repository free of SVN clutter.

The first thing we need to do is create a users file that maps all your SVN users to your GIT users. Just make a file on your Desktop named 'users.txt'. Map the users using this format:

jmaddox = Jon Maddox <jon@gmail.com>
bigpappa = Brian Biggs <bigpappa@gmail.com>

Simple. Now here are the commands you'll run. I'll explain them below.

mkdir my_blog_tmp
cd my_blog_tmp
git-svn init http://code.yoursite.net/my_blog/trunk/ --no-metadata
git config svn.authorsfile ~/Desktop/users.txt
git-svn fetch

The first two are self explanatory, we're making a new directory for the temporary repository. The second command initializes the directory as a git-svn hybrid thing and points the origin at your SVN repository. The flag, --no-metadata, tells GIT to leave all the SVN details behind (not the commit log). The fourth command tells GIT to remap all the SVN users to GIT users when it sucks down the source and history. The last command actually does the fetching.

Ok, so now after a few LONG minutes, your source is all there. Do a git log to see that your users have been mapped. Sweet!

Now you just have one last step. You need to clone this repository. Why do we do this? When doing a normal git clone it will take everything we want from the temporary repository, while leaving behind all the SVN cruft that was there to support the git-svn stuff.

git clone my_blog_tmp my_blog

Boom! You're done. Now you have a super clean GIT repository all ready to use.

Popularity: 54% [?]

    Categories: GIT, Snippets     17 Comments »

GIT It?

While working today I think I heard GIT mentioned on every form of communication I use daily. It was mentioned in several IRC channels, on twitter a ton, in an email, over IM, and a couple of new posts in my feeds. It has become obvious that GIT has hit the early adopter phase.

I'm not going to sell GIT or even try to explain why it's so great. There are tons of places online that already do that. I'm just going to share a couple stories.

Who Gives a Crap, I Gotta Get Work Done

This new source code management software that seems to be gaining a HUGE amount of steam first popped on my radar early last summer. I contemplated playing with it, but like most things, I skipped it. I figured as a single developer, it wouldn't mean much to me. I code,commit, iterate. "What do i need with fancy branching?" I said. But @peterc replied with my answer. I just didn't get it then.

Months went by as I used SVN like everyone else. I was just happy with versioned code, that's about all that SVN did for me.

RubyConf 2007

As I was outside with the rest of the Ruby Smoking Crew, I got Chris Wanstrath, unofficial GIT ambassador, to try to sell me on it. He started with the normal branching pitch, and I stoppped him.

"I don't branch".

"Because you don't use GIT".

BOOM. It hit me. I don't branch because branching with SVN sucks so much fucking arse that it's just not worth it. CERTAINLY not for changes that take only a few hours. With SVN you hang out on trunk and make your thousands of commits. Forget if you want to try something wacky real fast, you'd have to branch it! And thats just a whole lot of work.

Fast Forward a Few Days.

I'm sitting in a cube at Yahoo!. I'd been given a task a few days earlier. I was working on it and hit a stopping point. I needed to make a huge sweeping change. BUT, two hours later, I had to demo it to a room full of Yahoo! people I had never even met. AND they expected it to work. I knew my changes were going to break the whole app for a little while.

Ok, so first off, this project was neither IN a repository, nor did I even have access to one. I'd only been there for like two days. So I could copy my source directory and file it away for the demo, or... I could finally throw GIT on my laptop and try it out! So I installed GIT, initialized my rep. Branched it...whoa what? Thats it. git checkout -b new_model? Thats it?! SICK.

I continued my work and when it came time for the demo I just used git checkout master and voila, I was back to my fully working copy. I finally 'got' GIT. At least the branching part. Not only is it easy to branch, you can branch locally. And by locally, I mean privately. So if you want to try something weird and crazy out, you don't need to worry about making a new branch at the central repository, just branch it locally and go to town. If it worked out, merge it back into master. If it doesn't, just dump it. Now, like most GIT users, I don't even work directly on master.

Ok, thats my story. I guess the moral is, you're never going to get why something is good for YOU until YOU use it. Everyone takes different things away from products, especially when you're talking about productivity.

Popularity: 17% [?]

    Categories: GIT, Tools     1 Comment »