Git For Dummies...

Tagged as Programming

Written on 2009-10-22 19:53:02

A friend asked me for a simple tutorial. So here one is. Also, just because I can:

My workflow roughly looks like:

Start or clone git repository: [git clone $URL] OR [mkdir project; cd project; git init]
Make some changes: HACK HACK HACK, ensure the files are tracked: [git add $FILES]
Review my changes: [git status], [git diff]
Uh oh, a choice!: if (I like these changes)
then [git commit] // ideally, your $EDITOR environment variable is set to the editor you like.
else [git checkout -- $FILES] // yes, the dashes should literally be there. this reverts the files to the last commit's state.
Repeat.


I didn't cover pushing and pulling (collaborating) or branching above (working on separate features simultaneously).
Let's do that now:

Get a list of branches and show the current branch: [git branch]
Start a new branch to work on: [git branch $NAME]
Switch to a different branch: [git checkout $NAME]
Delete a branch you don't want anymore or are finished with: [git branch -d $NAME]
Merge changes from one branch into another branch: [git merge $SENDER $RECIPIENT] // Branch recipient gets senders changes.
List tracked repos (online, github, etc): [git remote]
Track a friends repo (or one online, github, etc): [git remote add $URL]
Send your changes to a repo you have write access to: [git push $REMOTE $NAME] /* remote can be a url or one of your remotes.
name is a branch on your machine. note that master is a branch. */
Retrieve and merge in a friends changes: [git pull $REMOTE $NAME]

There are a bunch of blog tutorials. The best way to find them is to go to programming.reddit.com and search for "git tutorial" or "git intro".

Other than that, there are two free git books I know of:
Pro Git - http://progit.org/book/
The Git Community Book - http://book.git-scm.com/
comments powered by Disqus

Unless otherwise credited all material Creative Commons License by Brit Butler