I'm playing with Git in isolation on my own machine, and I find it difficult to maintain a mental model of all my branches and commits. I know I can do a git log
to see the commit history from where I am, but is there a way to see the entire branch topography, something like these ASCII maps that seem to be used everywhere for explaining branches?
.-A---M---N---O---P / / / / / I B C D E \ / / / / `-------------'
It just feels like someone coming along and trying to pick up my repository would have difficulty working out exactly what was going on.
I guess I'm influenced by AccuRev's stream browser...
Use git log --graph
or gitk
. (Both also accept --all
, which will show all the branches instead of just the current one.)
For branch names and a compact view, try:
git log --graph --decorate --oneline
I have 3 aliases (and 4 alias-aliases for quick usage) that I normally throw in my ~/.gitconfig
file:
[alias] lg = lg1 lg1 = lg1-specific --all lg2 = lg2-specific --all lg3 = lg3-specific --all lg1-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)' lg2-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(auto)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' lg3-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset) %C(bold cyan)(committed: %cD)%C(reset) %C(auto)%d%C(reset)%n'' %C(white)%s%C(reset)%n'' %C(dim white)- %an <%ae> %C(reset) %C(dim white)(committer: %cn <%ce>)%C(reset)'
git lg
/git lg1
looks like this:
git lg2
looks like this:
and git lg3
looks like this:
It should be noted that this isn't meant as a end-all-be-all solution— it's a template for you to change, add to and fix up to your liking. If you want to use these, my recommendation is to:
.gitconfig
,.gitconfig
s in the future (or alternatively version control your dotfiles, of course).Note: Answer copied from and improved upon the answer at stackoverflow.com/questions/1057564/pretty-git-branch-graphs since it's far more appropriate here than it was there. Left the copy on the other question for historical reasons— it's closed now, and the answer's referenced by a bunch of other answers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With