git-ify your command line!
In a nutshell: Run bash < <(curl -s https://raw.github.com/gurdotan/gitify/master/gitify ) and get lots of nice command line goodies for git (test only on Ubuntu).  Note: running this will not include the utilities detailed below in sections 1 & 5. In detail: Iâve been working with git a lot lately, though I admit, still at a basic level.  Though I enjoy git a great deal more than SVN, the problem with git is its lack of friendliness in the command line.  The commands are too long to type, you never know which branch youâre currently on, commits and merges are sometimes mistakenly done in the wrong place, feature branches are hard trace from where they originated, diffs are hard to read, history graphs are too verbose⊠Over time, I found myself gathering more and more command line tools that make life easier.  Letâs checkâem out: 1. Branch name in command line prompt Instead of just seeing the folder youâre in: /path/to/git/repo$ You can also see the branch youâre on: /path/to/git/repo[master]$ And, better yet, you can see if the branch is dirty with uncommitted changes (note the small asterisk): /path/to/git/repo[master*]$ To empower your CLI with this feature, add the following to your shell profile (I work on Ubuntu so ~/.bashrc in my case): function parse_git_dirty { [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*" } function parse_git_branch { git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/" } export PS1='\u@\h \[\033[1;33m\]\w\[\033[0m\]$(parse_git_branch)$ ' Iâm totally addicted to this wicked CLI upgrade, canât work without it nowadays.  Thanks to Henrik Nyh.  Iâve seen lots of other variations on the web for this, but I like hisâ the best. Update: You can also use the following snippet to also get a little plus sign (/path/to/git/repo[master+]$) when the local repo is ahead of the remote repo, i.e. you have unpushed commits. Thanks to Paul! function parse_git_dirty { if [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]]; then echo "*" elif (( $(git status 2> /dev/null | grep 'Your branch is ahead of' | wc -l) != 0 )); then echo "+" fi } 2. Common shortcuts (git aliases) I use the following shortcuts (some were inspired by previous workings with SVN): /path/to/git/repo[master]$ git st # == git status /path/to/git/repo[master]$ git br # == git branch /path/to/git/repo[master]$ git co someBranch # == git checkout someBranch /path/to/git/repo[master]$ git ci -m"message" # == git commit -m"message" /path/to/git/repo[master]$ git df # == git diff To get these aliases up and running just run the following lines in your command line: git config â-global alias.st status git config --global alias.br branch git config --global alias.co checkout git config --global alias.ci checkin git config --global alias.df diff 3. Avoiding fast-forward merges This is just another alias, though I think itâs worth mentioning in detail.  In git, when you create a new branch and start working on it, once you decide to merge back to the originating branch, if that originating branch hasnât diverged yet (i.e. received more commits), git doesnât really perform a merge.  What it actually does is change the original branchâs pointer to point to the last commit on the new branch, resulting in both the original branch and the new branch pointing to the same last commit.  The trouble with this feature is that if you want to trace back where youâre branch originated from, the history graph wonât show the intersecting commit where you branched out.  So if for some reason you need to revert the work done on this branch youâll have to manually sift through git logâs historical commit messages and try to remember where you started your branch - a serious headache?  Instead, I regularly commit with: /path/to/git/repo[master]$ git nffmerge someBranch which is just an alias to gitâs regular commit command but with fast-foward flagged off: git config --add alias.nffmerge 'merge --no-ff' An excellent resource to understand this better is Vincent Driessenâs git branching model 4. History graphs (git log) git log just doesnât cut it for me.  Thereâs too much clutter on the screen that you canât really read.  I suggest using this simple alias: git config --global alias.logk "log --graph --pretty=oneline --abbrev-commit --decorate" # Now use it: /path/to/git/repo[master]$ git logk Then git logk will generate a nice flat looking log which is easier to read: ïżŒ But the real bomb (wait for itâŠ), is the colorful history graph that shows relative commit time and commiter names.  Donât just stand there, you have to try this one out: git config --global alias.log-color "log --graph --full-history --all --color --pretty=format:'%x1b[31m%h%x09%x1b[32m %C(white)- %d%x1b[0m%x20%s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --date=relative" # Now use it: /path/to/git/repo[master]$ git log-color And hereâs how it looks: ïżŒ Thanks to Bartâs blog and some random dudes on stackoverflow.com. 5. Whole project diff (git diffall) Sometimes Iâd like to see a diffs of all changed files in my project in a tree view of the folder structure (like Winmerge, Tortoise and other Windows tools).  The solution is to combine git-diffall with a GUI diff tool (meld in my case): ïżŒ To do this, you need to install git-diffall and configure git to use it: git clone https://github.com/thenigan/git-diffall.git ~/tools/git-diffall sudo ln -s ~/tools/git-diffall/git-diffall /usr/bin/git-diffall git config --global diff.tool "meld" git config --global diff.external "meld" # Now use it: /path/to/git/repo[master*]$ git diffall You can also you git-meld which is very similar and also a good tool. Conclusion Git is awesome compared to some older source control systems Iâve worked with (CVS, SVN, Clearcase to name a few).  The fact that branching and merging is so easy and fast really transforms your work flow.  With just a bit of command line hacking, you can make your life a lot easier. If anyone out there has more git command line productivity tips, do share!

















