3

I've been working on a system to keep a BRANCH_DESCRIPTION file whenever I create a topic branch in git. Like others have mentioned, I too sometimes forget what I created a branch for, even though I try to give it a descriptive name.

I have been primarily working off the SO question How do I tell git to always select my local version for conflicted merges on a specific file?, but I've run into a case where the custom merge driver does not get called, so the file from the topic branch being merged in overwrites the local branch. For example:

git checkout master
echo "mainline" > BRANCH_DESCRIPTION
git add BRANCH_DESCRIPTION
git commit -m'Added BRANCH_DESCRIPTION file'
git checkout -b topic_branch
echo "this branch is used to fix the bug where [...]" > BRANCH_DESCRIPTION
git commit -m'Updated BRANCH_DESCRIPTION'
[code, code, code ...]
[git, git, git ...]
git checkout master
git merge --no-ff topic_branch

At this point BRANCH_DESCRIPTION will simply be overwritten since the master branch's description has not changed regardless if a custom merge driver has been setup for the file.

Any ideas?

Community
  • 1
  • 1
berto
  • 8,215
  • 4
  • 25
  • 21
  • What is your rationale for storing a branch description in the content being track? – CB Bailey Aug 29 '11 at 07:01
  • I'm not particularly attached to the idea. The other SO question http://stackoverflow.com/questions/2108405/branch-descriptions-in-git got me going in this direction and so I started checking it out. What I believe you are alluding to is that this information is more metadata than content that should be tracked? – berto Aug 29 '11 at 16:33

2 Answers2

10

Git now supports this by running git branch --edit-description

This answer has a nice writeup

Community
  • 1
  • 1
Jason Axelson
  • 4,485
  • 4
  • 48
  • 56
4

Try using git notes for this purpose.

In your branch do git notes add -m "this branch is for blah blah"

Then write a post-commit in your repo with the following:

#!/bin/sh
git notes show HEAD~1
git notes copy HEAD~1 HEAD

Additionally add a git notes remove HEAD~1 if you want.

Use git notes show to see what the branch is for.

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • 2
    I have been experimenting with this and noticed that using "git reset" will lose the note. I'm guessing an alias on git reset could fix this case. – berto Sep 10 '11 at 16:54