28

I'm doing some exploratory work where I will most likely be spending 30 min on several different variations of the same task. I want to track them in git so I can jump back and forth between approaches. And if there are 3 or 6 or 9 branches, I might need some more info than the branch name to tell them apart.

What is the cleanest way to attach a comment to a new branch?

doub1ejack
  • 9,047
  • 15
  • 60
  • 110
  • 1
    Possible duplicate of [Branch descriptions in git](http://stackoverflow.com/questions/2108405/branch-descriptions-in-git) – phuclv May 18 '17 at 04:25
  • [How do you annotate a branch?](http://stackoverflow.com/q/4750845/995714) – phuclv May 18 '17 at 04:25

1 Answers1

51

You want branch descriptions:

git branch --edit-description

This will open up your editor and let you attach metadata to the branch. You can extract it with:

git config branch.<branch>.description

A couple of important notes:

  1. This is stored locally. By definition it can't be pushed since it's stored in .git/config. All the same it works great for this use case.

  2. If you delete the branch, the description will delete as well.

  3. You can push this description into merge commits if you set git config --global branchdesc true. This means when you issue git merge --log <branch>, it'll force the branch description into the stock merge commit message. This has a lot of uses. For example, this is how I track topic branch release notes at my employer.

Christopher
  • 36,834
  • 9
  • 72
  • 91
  • Perhaps the branchdesc configuration name has changed to merge.branchdesc? https://git-scm.com/docs/merge-config#merge-config-mergebranchdesc . – Michael Welch Aug 28 '18 at 14:46
  • Why do we need `--log` in that merge command? What will happen if I omit it? – Sergey Zakharov Nov 27 '19 at 13:09
  • @MichaelWelch It has always been [merge.branchdesc](https://github.com/git/git/commit/898eacd8ada2d012f977948350ed60845e238037#diff-46010cf892c0bcda3accdacd4c2faa7f356659d9bd9347d4fb67fb187a9734dfR27). – krisz Nov 23 '20 at 00:49