The Git Get By List

Git for me is THE best and most powerful source control system around. I can’t imagine developing without it anymore such is the flexibility and control it gives me over all other source control systems I’ve used. For my own reference purposes and as a quick goto/reminder list, here is a bunch of my most common Git commands that I use on a daily basis. Of course, there are so many git commands that I probably haven’t even used most of them but these are what currently work for me.

git status

Simply shows the current state of affairs of the repository. What’s being tracked, what isn’t, etc.

git remote add origin "<path/to/remote/repo>"

Add a remote location to push to/pull from. This is set automatically when cloning

git log --pretty=oneline

Simple, succinct log

git checkout -b mynewbranch

Creates a new branch “mynewbranch” and checks it out at the same time

git branch -d mynewbranch

Delete “mynewbranch” locally

git push :mynewbranch

If you pushed the branch then this deletes it on the remote

git pull --rebase

Grabs latest changes from origin, rewinds your changes, then plays them back over the top of the pulled changes. I use this over git pull, git merge, and git fetch all the time as I think the history looks better/cleaner in gitk and I seem to get fewer conflicts this way

git add -A

Adds all files to the staging area, both updated and new files, as well as those marked for delete

git rm --cached <file> 

Removes file from staging after the result of a git add command

git diff --cached 

Shows the differences between original and changed files after adding them to the staging area

git commit -m "commit message"

Commits the staged changes

git commit --amend

Adds currently staged changes to the previous commit. Useful for when you should have added them previously but forgot!

git reset --soft HEAD^

Undoes the last commit putting the files back in the staging area. Keep re-issuing to undo one commit at a time. Useful if you forget to add a file or hunk as long as you haven’t already pushed to other users.

git clean

Removes untracked files from working directory. Use the -n (–dryrun) option to see what will be affected and -f to make it happen

git reflog

Shows every action taken on the repository and even contains any commits you may have lost and want to retrieve (as long as you haven’t done a garbage collection). Useful for getting back into a good state to undo the damage you did with a previous command!

git gui

Visual tool to help see what’s staged, what’s not, and an easier way to stage hunks rather than whole files

gitk --all

Visual tool to see all the changes in the repository. The –all flag means include all branches

There’s obviously a whole lot more but these get me by for the most part. I’ll keep adding more as and when they creep into my daily usage but for now this is what keeps me productive.

Advertisements
The Git Get By List

2011 Review

Just had to get a quick end of year post up. Yep, it’s new years eve, I’ve just finished watching Rise of The Planet Of The Apes (not bad), had too much beer (not good), and thought it would be a good idea to ramble on here for a while. At the very least it’s a good excuse to use my shiny new quad-core iMac so here goes.

2011 for me wasn’t too bad. I started a blog! I even started a new job in March, got stuck into NServiceBus for a good while and really enjoyed it. It’s a great framework for reliable, durable messaging and I thoroughly recommend it. On the subject of messaging, one really interesting library that I’ve spent a little bit of time looking at is ZeroMQ, a socket library that has the familiar messaging patterns at it’s heart even though it’s not a servicebus. Wow, that thing is fast! I’ll definitely be evaluating it in more depth over the next few months.

Toward the latter part of the year I got into Android development using Eclipse and Java. I wrote an order tracking application in my spare time and then unveiled it at work where it was received as I hoped it would be. This led to further ideas about where we could go with mobile dev. The obvious conclusion being that you can’t do mobile only for one platform so some time was spent evaluating the best way to target the iPhone as well as Android. In then end it looks like the fantastic work that’s gone into the Mono framework and MonoTouch and Mono for Android in particular means that we can make the best use of our existing in-house C# skills to get mobile apps out there way quicker than we ever could have done if we’d had to learn each platform from scratch. That’s not to say the time writing the Java version was wasted, it wasn’t. In fact, knowing key Android Concepts such as Activities and Intents are still crucial when using Mono. This knowledge helped me port the Java version to Mono in record time – about a week – and I’m already about 50% of the way into a MonoTouch iPhone version.

My current favourite Git hosting provider (www.bitbucket.org) also released a free Git Gui tool for Mac OS X in the Mac App Store called SourceTree. I have to say, that despite being used to the command line when working with Git, SourceTree is so damn good I just have to use it, and best of all, it’s free so that’s another recommendation.

Goals for next year include really attacking Android and iPhone development. Mobile is definitely where it’s at/going to be, and I think Mono is the best tool to take me there in the shortest time. I may even get into targeting the Mac App store with it too. I wouldn’t mind learning a little bit of Ruby just for the hell of it. I’m trying to get my 13 year old daughter interested in programming and thought Ruby might be a good place to start, especially with KidsRuby. Looks like a really cool way to get children involved.

Okay, where I am, it’s 11:30-ish. Half an hour to go until I have to start putting those plans in place. Time to get another drink.

Happy New Year.

2011 Review