Ready GIT set GO

Better tools create better products. Here are a few things that you can configure to make your git experience better. If you have a suggestion, please share via comments.

1. Check Git version

$ which git
$ git –version

2. Check git config default username, email

$ git config –global “Your Name Here”
$ git config –global “”
$ git config –global color.ui true

To see the config settings for a particular git repository, you can run from the top level folder.
$ cat .git/config

3. Git shortcuts

There is a better way to configure git aliases inside git config, I personally prefer using bash shortcuts instead.
$ vi ~/.bash_profile
#git shortcuts
alias gs=’git status’
alias gb=’git branch’
alias gd=’git diff’
alias gc=’git checkout’
alias gsh=’git show’
alias gf=’git show –name-only’
alias gcon=’cat .git/config’
alias master=’git checkout master’
alias chekcout=checkout
alias cherry=’git cherry-pick’
alias unstage=’git reset HEAD’

I really do not want to remember the syntax for unstaging a file. If I want to unstage a file, I type unstage.

4. Git log format

$ vi ~/.bash_profile
# git pretty log
alias gp=’git log –pretty=oneline’
alias gl=”git log –graph –pretty=format:’%Cred%h%Creset -%C(yellow)%d%Crese t %s %Cgreen(%cr) %C(bold blue)%Creset’ –abbrev-commit –date=relative”
$ gl -20

The default git log format is very verbose and when you grep for a particular keyword, it is much easier to all details of the commit. Example.
$ gl -100 | grep “autocomplete”

5. Git autocomplete

When you install git, you get autocomplete scripts for free. Just add them to your bash profile, and you are all set. You may also want to look at other contrib scripts that might be of help to you. E.g. git hooks, emacs/vim highlighting etc.
$ vi ~/.bash_profile
# Set git autocompletion
if [ -f /usr/local/git/contrib/completion/git-completion.bash ]; then
. /usr/local/git/contrib/completion/git-completion.bash

if [ -f /opt/local/etc/bash_completion ]; then
. /opt/local/etc/bash_completion

6. Git Branch on command prompt

Rather than doing a git branch to identify the current branch you are on, you can display the current branch on the prompt string. There are also other indicators which will be helpful, especially during merge conflicts.
$ vi ~/.bash_profile
# set up PS1 for git
export PS1=”$BLACK\u@Macbook \w$RED\$(__git_ps1) $GREEN\$ ”

7. Git Ignore File

$ vi ~/.gitignore
Github has a good collection of example files.

Have a git config example that you like to share? Please drop a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *