Faster Git with Aliases (or is it Aliii?)

With git’s easy branching, I’ve gotten into a pretty good rhythm. Every time I start a task (more than just a quick fix) I do this:

git branch iliketurtles
git push origin iliketurtles
git branch -f iliketurtles origin/iliketurtles
git checkout iliketurtles

I’m basically starting a new local branch, pushing it to the remote repository, connecting the two for tracking, and checking out the local copy to work on. You can see that this is a lot of repetition, regardless of your feelings toward turtles. That’s where git’s aliasing comes in. Add these lines to the .gitconfig file in your home directory:

    launch = !sh -c 'git branch $1 && git push origin $1 && git branch -f $1
 origin/$1 && git checkout $1' -

It’s a long line, granted. It’s basically doing all the things listed above, in order. It’s like a slightly more complicated version of a shell alias, but with the benefit of…I guess being able to tell people you’ve written custom git aliases. Anyhow, I can now replace the four lines of git commands above with this:

git launch iliketurtles

The local and remote branches have been created and connected, and I’m now on the new branch. When I’m done with my changes I merge back into the main branch. From there, I need to wipe the temporary branch out of existance, like so:

git push origin :iliketurtles
git branch -r iliketurtles

I was using "git branch -dr iliketurtles" to remove the remote branch, until I realized it still leaves the branch on the remote repository. It only removes your ability to see it. This is the same approach taken when directors use softer lighting on Madonna. "git push origin :iliketurtles" removes the old branch completely. This is the same approach taken when MTV starts replacing Madonna videos with Lady GaGa. Still painful, but with less baggage.


Tags: , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: