How do you comment on the thread?

Is there a way to annotate a branch? It would be nice to do something like:

 $ git notes add branch-name -m 'This branch is for whatever'

but this, of course, is not very useful, since the note refers to the current heading of the branch, and not to the branch itself.

An easy workaround is to reset the README.branch name in the repository, but that seems awkward. A little more elegant is the presence of an orphaned branch containing only README.branch-names. I'm looking for a way to record that the target of a branch does not just put it in a commit message for the "first" commit of the branch. I put the "first" in quotation marks, because it is not always clear what is meant by this, which is the reason that it is inconvenient to put a discussion in a commit message. It is often difficult to find a commit in which such a message is recorded.

+46
git
Jan 20 '11 at 18:13
source share
6 answers

This would be a completely different approach than git note but you could use git config for this function.

 $ git config branch.<branch-name>.note 'This is what this branch is for' 

It could be an alias to make the interface easier (I think it can be improved, but this is what I use):

 $ git config alias.branch-note '!git config branch.$(git symbolic-ref --short HEAD).note $( if [ $# -gt 0 ]; then $1; fi)' 

This allows you to set the note for the branch as follows (make sure you specify in the note):

 $ git branch-note 'This is what this branch is for' 

Then you can get the current note branch as follows:

 $ git branch-note This is what this branch is for 

As an added benefit, the configuration entries defined in branch.<branch-name> of branch.<branch-name> names branch.<branch-name> will follow the renaming of the branch and will be automatically cleared if you delete the branch later. These extra configuration entries will only be saved as long as the branch exists, at which point they will be automatically deleted.

The disadvantage of this approach is that you can only store one โ€œnoteโ€ for each branch. Subsequent branch calls with an argument will overwrite the previous branch. You also do not benefit from storing the message in a monitored git object, but perhaps this will be enough for your purposes.

+38
Jan 21 '11 at 4:01
source share

I like to do an empty commit whenever I create a new branch, with a commit message saying what needs to be said.

 git branch BA git checkout B git commit --allow-empty -m "Created branch 'B' from 'A'" 

This also has a wonderful side effect of creating the story shown in "git log -graph" much clearer - namely, it shows a clearly marked fork in the tree at the time I created the branch, instead of what I usually get that is incomprehensible unlabeled with a fork at a later time when I complete my first commission while in B - such a thing keeps me in constant fog.

+10
Jul 15 '15 at 21:53
source share

Using Brian's solution, I created git-note . You can use it like:

 $ git note "Some note" # set note for current branch $ git note -b branch # see note for branch $ git note -l # list all the branches with theirs' notes 
+4
Oct 17
source share

The correct answer to this is now branch descriptions, a function that was added to git after this question was originally asked.

Here are two questions that trigger this answer: Industry descriptions in git Can I add a message / note / comment when creating a new branch in Git?

+3
Mar 17 '16 at 14:47
source share

You can simply create a โ€œbug trackingโ€ in your tracker problem, where you detail a big new feature, with layouts and UML diagrams and all, and then name the bug1234 branch.

+2
Jan 23 '11 at 21:30
source share

No. Notes are tied to specific commit identifiers.

0
Jan 20 '11 at 18:16
source share



All Articles