I read Phil Haacks great post on using aliases and my life has never been the same. Below is just a quick list of the Git aliases i've adopted and added to make Git an afterthought during work.
One quick note about the benefits of using Git in a terminal/bash over a GUI/VS plugins. It gives you full history of your Git activity within the same window, more transparency on what's happening, better understanding of git, and it's likely more powerful since there are so many commands and options in Git that it's hard for a GUI to handle all of those scenarios. While I preferred a GUI in Subversion, bash turns out to be much more efficient in Git.
Aliases are saved in .gitconfig file under [Alias] section. This file can be found in home folder on the mac (you can open it from terminal like this: open ~/.gitconfig or open $HOME/.gitconfig ) or in in windows it's here: c:\users\myusername. You can see my .gitconifg here.
List all aliases
aliases = config --get-regexp alias
s = status
co = checkout
git co master
git co someBranch
Add and Commit
cm = !git add -A && git commit -m
git cm "my awesome funny comment"
Pull and Rebase
p = pull --rebase
git p origin mybranch
Pull Rebase, Push to Master
ppm = !git pull --rebase && git push origin master
git ppm <- this will pull & rebase (merge and replay your changes on top). If there are merge issues it will stop there so you have a chance to correct conflicts before continuing!
Show Differences Between 2 branches
rcdiff = !git diff --name-status master rc | grep -v "AssemblyInfo.cs"
git rcdiff <- show difference between MASTER and RC branches, ignore AssemblyInfo.cs files
especially useful when working with a longer term feature branch
Push to Remote Master
pm = push origin master
Skip Fwd/Bwd through commit history
fwd = !git checkout `git log --reverse --ancestry-path HEAD..master | head -n 1 | cut -d \ -f 2`
rwd = !git checkout HEAD~
git fwd <- move head one commit backwards
git rwd <- move head one commit forward
there are 3 aliases here:
h - show nicely formatted commit history
hs - same as above, but show only n last entries
fh - show which files were checked in and by whom (grouped by commit).
h = !git log --graph --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
hs = !git h --max-count=10
notice that it also shows that I am ahead of remote master by 1 commit. This will also show local branches and stash!
fh = !git log --format=format:'%C(bold cyan)%ar %C(reset) %C(green)%f' --name-status
Turn Proxy On/Off
useful in corporate environments.
you can also add --global flag here but I found that not including it works best when you want some repos to work locally while others going out over a proxy. That way you don't have to keep flipping it back and forth
This may seem like a large list (few more in the file), but mainly the workflow is very simple! every time I'm ready to check in I do this:
git s // status, what was changed git diff // confirm changes git cm "finished feature A" // commit git p // pull and rebase to make sure there are no conflicts with remote git pm // push remote master