Displaying a hierarchy of branches on the command line?

I am curious if there is a way to show the hierarchy of branches on the command line? For example, if I use git branch instead of seeing the output as follows:

 * master joes_work refactoring experiment 

You see the output as follows:

 * master joes_work refactoring experiment 

Thus, it is easy to see which branch has a particular branch. Even if there is no specific command that displays the tree structure, is there a command that displays information about which branch came from which branch? I can use perl script to format the output.

+61
git
01 Oct 2018-11-11T00:
source share
6 answers
Decision

sehe looks great, here is another one that seems to contain similar information, formatted differently, it uses git log, so it also contains commit information (ignore branch names, I 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 
+84
01 Oct '11 at
source share

Try

 git show-branch git show-branch --all 

Output Example:

 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 
+21
01 Oct '11 at
source share

This is not how git branches work. If I make some commits for branch a , create branch b from it, work there, and then do other work on a :

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

This is indistinguishable if you did it the other way around:

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

The only way I can find out from which branch some branch came from is to reflog, but this is unreliable (records older than 90 days are usually deleted).

+5
Oct 01 '11 at
source share

For me, gitk is the easiest solution for this. Although it will not show you command mode, it will automatically populate a nice interface like this:

enter image description here

+1
Dec 03 '18 at 7:04
source share

I want to complete @ctcherry's answer.

I like it when I also see the user who committed and the date, so use the following line:

 git log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit 

However, this is a rather long line that is hard to remember, so you can use an alias. You should use this in your terminal:

git config --global alias.lg "HERE GOES MY BIG LOG COMMAND LINE"




To summarize, copy and paste the line below into your terminal:

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

Then you just need to use git lg to get the log history tree.

Example: enter image description here

CSI

0
Dec 19 '18 at 15:10
source share

How about this alias for your .gitconfig :

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

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

-one
Dec 30 '15 at 16:07
source share



All Articles