Showing branch hierarchy at the command line?

I’m curious if there is a way to show branch hierarchy on the command line? For instance if I use git branch, instead of seeing output like this:

* master
joes_work
refactoring
experiment

You see output like this:

  • Why is github showing different authorname?
  • HG: Match remote repo's changesets
  • Git - remove remote branch with a space in the branch name
  • Git failing to ignore .DS_Store defined in global ignore
  • how can I do a git pull in the gitg / gitx visual tool?
  • Git change source of new branch to older commit of source branch
  • * master
        joes_work
        refactoring
            experiment
    

    That way it’s easy to see which branch a particular branch.. branched off of. Even if there’s no specific command that outputs a tree structure, is there a command that outputs information on which branch came from which branch? I can use a perl script to format the output.

  • can not get new branch from github
  • Git review systems
  • Reset or revert a specific file to a specific revision using Git?
  • Execute PHP from GIT post-update hook
  • Should CodeLite workspaces be shared?
  • Migrate single repository from one Atlassian stash server to another server and maintain all data
  • 4 Solutions collect form web for “Showing branch hierarchy at the command line?”

    sehe’s solution looks great, here is another one that seems to contain similar information, formatted differently, it uses git log, so it contains commit information as well (ignore the branch names, I kind of messed them up!):

    git log --all --graph --decorate --oneline --simplify-by-decoration
    
    * ae038ad (HEAD, branch2-1) add content to tmp1
    | * f5a0029 (branch2-1-1) Add another
    |/  
    * 3e56666 (branch1) Second wave of commits
    | * 6c9af2a (branch1-2) add thing
    |/  
    * bfcf30a (master) commit 1
    

    Try

    git show-branch
    git show-branch --all
    

    Example output:

    bash$ git show-branch --all
    ! [branchA] commitA only in branchA
     * [branchB] commitB
      ! [branchC] commitC only in branchC
    ---------------------
    +   [branchA] commitA only in branchA 
     *  [branchB] commitB
      + [branchC] commitC only in branchC
     *+ [branchC~1] commitB-1 also in branchC
     *+ [branchC~2] commitB-2 also in branchC
    +++ [branchC~3] common ancestor
    +++ [branchC~4] more common ancestors
    

    That’s not how branches work from git’s point of view. If I make some commits to branch a, create branch b from it, work there, and then do other work back on a:

    A -- B -- D <-- a
           \
            \
              C <-- b
    

    That’s indistinguishable if you did it the other way around:

    A -- B -- C <-- b
           \
            \
              D <-- a
    

    The only way I can think of to find out from which branch certain branch originated is the reflog, but that’s unreliable (entries older than 90 days are usually deleted).

    How about this alias for your .gitconfig:

    [alias]
    branch-tree = !cd "$(git rev-parse --git-dir)/refs/heads" && tree
    

    You can also give options, depending on what your tree command supports, such as -D for timestamps.

    Git Baby is a git and github fan, let's start git clone.