If you don’t know GIT yet it is a software version control system like Subversion, CVS or Perforce. It was primary developed by Linus Torvalds for Linux kernel development. I have started using GIT in the beginning of 2009 and I must say that after a not so small learning curve I really like it and see all the benefits especially when it comes to collaboration.
There are alternatives but GitHub is currently the best service to use GIT. You can host open source projects for free and the pricing for private projects is not too expensive. Check out my GitHub profile with my open source projects here.
To get started you should first install GIT on your machine and read the docs.
The tooling support around GIT is perhaps not as extensive like for other VCS yet, so if you are afraid of using the console GIT might not be right for you. However, there are already great tools around but for many things I am still using the Terminal.
Custom Bash Prompt
I am using a custom bash prompt which indicates on which branch you are and further color highlighting helps to keep track:
Eclipse Plugin
My main IDE is Eclipse with Flash Builder or FDT so the Eclipse EGIT plugin is really a must have:
Merge Tool
Merging is an important task when working in a team. GIT is really flexible and you can configure it to use 3rd party apps for merging. I am not a big Perforce fan but the free p4merge tool is really great. Check out the blog post by Andy McIntosh for a detailed explanation how to set it up.
GitX
GitX is maybe the best tool to visualize the branch history but I must say that I don’t use it in my daily work. It can also be used to create commits and revert changes etc.
Links
- GIT – SVN
- A GIT workflow for agile teams
- Agile GIT and the story branch pattern
- Understanding GIT conceptually
- Merge vs. Rebase
- Squashing commits with rebase
- GitHub Post-Receive hook for Pivotal Tracker
- TortoiseGIT for Windows
Commands
If you are new to GIT it is hard to remember all the different commands. Here a list of commands which I use very often also as a reference for me
Create a local repository:
# clone an existing repository git clone [GITHUB_CLONE_URL] # or do it the long way: mkdir [PROJECT_DIR] cd [PROJECT_DIR] git init touch README git add README git commit -m 'first commit' git remote add origin [GITHUB_CLONE_URL] git push origin master
Changes and Commits:
# To see which files are changed and maybe not added yet to the repository use git status # Add a file to the repository git add [FILE] # or to add all untracked files git add . # revert a change git checkout -- [FILE] # when you are ready with a change git commit -am "[CHANGE_DESCRIPTION]" # a commit is only local so when you want to push it to the server git push origin [REMOTE_BRANCH_NAME]
Branches:
# Create remote branch git push origin master:[REMOTE_BRANCH_NAME] # Checkout and track remote branch git checkout --track -b [LOCAL_BRANCH_NAME] origin/[REMOTE_BRANCH_NAME] # local branch list git branch -l # remote branch list git branch -r
Tags: Every time you make a release or reach a milestone creating a tag is a good idea.
# Create tag git tag -a [TAG_NAME] -m "[TAG_DESCRIPTION]" # Push tag git push --tags origin master
Merge: You should work on a branch when implementing a new feature or story. If you are done you should merge this into the main branch.
# Switch to feature/story branch git checkout [STORY_BRANCH] # make changes and when done git commit -am "[DESCRIPTION]" # switch to master git checkout master # get all changes from master git pull # switch to story branch git checkout [STORY_BRANCH] # rebase story branch with master changes git rebase master # maybe solve conflicts git mergetool # switch back to master git checkout master # finally we can merge it in and there should be no conflict git merge [STORY_BRANCH] git push
Stash: When you have changes in your working directory and want to switch to another branch you can stash your changes.
# Create stash git stash # Apply git stash apply
When you migrate a project from SVN to GIT this comes in handy:
find . -name .svn -print0 | xargs -0 rm -rf
btw: GIT has only one .git directory and not one for every directory like SVN
If you have some commands which are important on a daily base please drop a comment so I can extend this post.







Thanks for this guide!