Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print branch description

Tags:

git

Git supports an option to the branch command called --edit-description which it states is used by "various" other commands. One command (at least by default) that it is not used by is git branch (when used to simply list the local branches). Is there a way to get git branch to show the branch descriptions (the verbose option looks like it just adds the last commit on the branch)?

To be clear, I'd like something like the following

> git branch
* master      I am the alpha and the omega
  bugfix1     This is the fix to that thing
  future      Transition to the new architecture
like image 386
bpw1621 Avatar asked Feb 25 '13 01:02

bpw1621


People also ask

How do I find my branch description?

To show description of a branch, use command git config branch. <branch name>. description .

What is a branch description?

1 : a part of a tree that grows out from the trunk or from a main division of the trunk. 2 : something extending from a main line or body like a branch a branch of a railroad. 3 : a division or subordinate part of something a branch of government The bank opened a new branch.

How can I tell which branch a branch is from?

You can use git branch --contains to list all the branches descended from the tip of develop , then use grep to make sure feature is among them. If it is among them, it will print " feature" to standard output and have a return code of 0.

What is the work of a branches?

A branch is a secondary wood limb growing from the trunk of a plant. It helps transport materials from the tree trunk to the leaves.


2 Answers

I confirm there is no way for now to display the description of the branch with git branch (as opposed to git config, see last part of this answer below).

This thread includes

The coming v1.7.9 will introduce branch description, mainly used in integration process. I think we could make it useful for users who don't extensively use request-pull/format-patch. Showing a short summary along with branch name in "git branch" would be nice.

I agree that it would be nice to give users access to the information even if the branch ends up being merged to the master branch by you and never leaves your repository by itself.

You however are misguided to say "Showing a short summary along...".

The branch description support is to give users a place to record detailed explanation about a branch, similar in size to what you would normally place in a log message of a commit or a cover letter of a series.
There wasn't any convenient place to do so for a branch that is (1) inherently a moving target while it is being developed and (2) is not a good match for tags and notes.

There already is a good place for a brief summary and it is called "branch name". Name your branches just like you name your functions.

The suggested patch "git branch --verbose-format" is not yet completed.

So the script mentioned by poke, remains (with a git alias) one possible solution:

#!/bin/perl
 
$output= `git branch`;
 
foreach my $line (split(/^/, $output)) {
  my ($is_current, $name) = split(/\s+/, $line);
  my $description = `git config branch.$name.description`;
 
  $description =~ s/\s+$//;
  printf("%1s %-22s %s\n", $is_current, $name, $description);
}

Philip Oakley suggests in the comments:

You can display the branch description using a git config command.

To show all branch descriptions, I have the alias

brshow = config --get-regexp 'branch.*.description'

, and for the current HEAD I have

brshow1 = !git config --get "branch.$(git rev-parse --abbrev-ref HEAD).description". 
like image 86
VonC Avatar answered Oct 13 '22 20:10

VonC


Hit this on terminal. This will display branches with description if your branch has some description.

Step 1:

vi ~/.bashrc

Step 2: Put this

alias git-describe-branches='for line in $(git branch); do 
     description=$(git config branch.$line.description)
     if [ -n "$description" ]; then
       echo "$line     $description"
     fi
done'

Step 3:

source ~/.bashrc

Step 4:

git-describe-branches

OR

for line in $(git branch); do 
     description=$(git config branch.$line.description)
     if [ -n "$description" ]; then
       echo "$line     $description"
     fi
done

Note:

  1. Run this in git working directory.

  2. Will show description if your branch has description.

like image 40
Sahil Gulati Avatar answered Oct 13 '22 20:10

Sahil Gulati