37

Is there a way to show only the branch structure in Git? There are a number of tools that show the commits graphically, but in my case the list is so long that it's impossible to see the structure. I guess git-log could be the answer, but I can't find any switches that only show the branching commits. This along with "--graph --branches --oneline --all" could do the trick.

EDIT: I'm looking for a way to do this in Ubuntu.

Makis
  • 12,468
  • 10
  • 62
  • 71
  • 1
    Possible duplicate of [Pretty git branch graphs](http://stackoverflow.com/questions/1057564/pretty-git-branch-graphs) – trblnc Jan 30 '17 at 11:48
  • Here's [a list of them from Git's official website](https://git-scm.com/downloads/guis/) and [a list of them from Wikipedia](https://en.m.wikipedia.org/wiki/Comparison_of_Git_GUIs) that may be of help. I suggest you to use [GitKraken](https://www.gitkraken.com/) to get such images. [![GitKraken](https://i.stack.imgur.com/vNp6k.png)](https://i.stack.imgur.com/vNp6k.png) – Gonçalo Peres Oct 11 '20 at 07:59

6 Answers6

40

I am not sure about what you mean by "branch structure".
git log can help visualize the branches made through commits (See this blog post):

[alias]
    lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"

alt text

But if you only wants the different HEAD branches, you could try something along the lines of:

heads = !"git log origin/master.. --format='%Cred%h%Creset;%C(yellow)%an%Creset;%H;%Cblue%f%Creset' | git name-rev --stdin --always --name-only | column -t -s';'"

(using the column command, and here only for commits since the last origin/master commit)

Note: Jakub Narębski recommands adding the option --simplify-by-decoration, see his answer.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This was pretty close (the latter solution), I just had to add the date and --branch to the command. Otherwise it only shows the current branch. Although it still doesn't leave out commits that are not the head. What I meant by "branch structure" is a way to see from what branch each branch is created, but with this command I can scroll through the list (which has about 350 commits) to see what has been going on. – Makis Sep 08 '10 at 12:34
  • @Makis: if you have a final command, you can post it as an answer: I am interested (and will vote it up). Then, you can even accept your own answer as the official one if you want. – VonC Sep 08 '10 at 13:26
  • I'm still looking into it, I'll be back at the office tomorrow to try to make sense of the structure. The repo was created with svn2git and I'm not 100% sure the svn repo was by the book either. – Makis Sep 08 '10 at 16:47
  • 1
    @Makis: Try `--simplify-by-decoration` option to git-log. – Jakub Narębski Sep 09 '10 at 22:47
  • This does the trick, thanks! Thanks for everyone else for your suggestions as well! – Makis Sep 15 '10 at 07:55
35

Perhaps what you want is --simplify-by-decoration option, see git log documentation:

--simplify-by-decoration

     Commits that are referred by some branch or tag are selected.

So it would be

git log --graph --simplify-by-decoration --all

or following VonC answer

git log --graph --simplify-by-decoration \
   --pretty=format:'%Cred%h%Creset-%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' \
   --abbrev-commit --date=relative
Community
  • 1
  • 1
Jakub Narębski
  • 309,089
  • 65
  • 217
  • 230
9

Maybe I'm missing something, but nobody seems to have mentioned gitk --all yet.

Benjol
  • 63,995
  • 54
  • 186
  • 268
  • 4
    I've just tried `gitk --all --simplify-by-decoration` and that works quite well. (That was with the gitk supplied with git 1.7.9.5) – Rhubbarb Oct 15 '13 at 17:41
6

Basic solution is:

git log --graph --all

If you want to get more fancy:

git log --graph --all --pretty=format:"%Cblue%h%Creset [%Cgreen%ar%Creset] %s%C(yellow)%d%Creset"
cmcginty
  • 113,384
  • 42
  • 163
  • 163
3

gitx if you are on a macOS

smartgit for macOS or Windows (but i have not used it)

git-gui to use the native git gui (cross-platform)

Azat Ibrakov
  • 9,998
  • 9
  • 38
  • 50
PurplePilot
  • 6,652
  • 7
  • 36
  • 42
2

To get more information on how a particular branch relates to other branches in your repository and remotes, you can use git wtf which is an add on script by William Morgan: http://git-wt-commit.rubyforge.org/

It produces summary information like:

$ git wtf
Local branch: master
[x] in sync with remote
Remote branch: origin/master (git@gitorious.org:willgit/mainline.git)
[x] in sync with local

Feature branches:
{ } origin/experimental is NOT merged in (1 commit ahead)
    - some tweaks i'm playing around with [80e5da1]
{ } origin/dont-assume-origin is NOT merged in (1 commit ahead)
    - guess primary remote repo from git config instead of assuming "origin" [23c96f1]

(example taken from the above URL).

Emil Sit
  • 22,894
  • 7
  • 53
  • 75