Getting more out of Git

Git is an awesome tool, here are some tips to get even more out of it. Of course theses apply only for the command line version of Git.

Global .gitignore file

You can make a global .gitignore file to excludes common filetypes that you know you don't want or don't need to track. To set it up you can run this command:
$ git config --global core.excludesfile path-to-your-excludes-file
Here is my gitignore file

Git colors

You can add color to your git output by running this command:
$ git config color.ui true

Git add --all

The command git add --all is a really great command, with it you can add a full directory, new, deleted or updated files. My alias is git aa
$ git config --global alias.aa 'add --all'

Git diff --cached

This command allow you to see the diff of the staged files. My alias is git dc
$ git config --global alias.dc 'git diff --cached'

Stage parts of files

If you add the '-p' flag to git add or git add --all you will see the diff of each files one by one, you can then type 's' to split the file and choose 'y' or 'n' to stage the file or ignore the changes. You can press '?' to get a list of all the options. This command is extremely useful to make good and relevant commits.

Stashing

If you don't want to commit your work in progress but need to switch branch, or work on something else temporarily, you can git stash your working directory and reapply these changes later. Use git stash apply to apply your last stash. If you have more than one stash, you can issue the command 'git stash list' to see your stack and use the command git stash apply [email protected]{#} to apply the stash that you want.

Rebase

With the command git rebase you can apply all the commit of branch on top of the current branch. When you merge a branch with git merge it creates "merge bubbles", you have points in your history where a bunch of changes are applied at the same time, if a bug is introduced, it's really hard to find which commit is responsible. It is a quite complex subject so I would recommend reading more about it here

Prettier Output

You can use this command to get Prettier git log output
pretty=format:%C(yellow)%h%Creset -%C(red)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset
That's all for now, I invite you to have a look at my GitConfigs on Github