Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add a message/note/comment when creating a new branch in Git?

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?

like image 260
doub1ejack Avatar asked Aug 09 '12 14:08

doub1ejack


People also ask

How do I add a description to a git branch?

To describe a branch, use git branch --edit-description , edit the opened file, save and exit.

What happens when you create a new branch in git?

Creating a new branch allows you to isolate your changes from the master branch. If your experimentation goes well you always have the option to merge your changes into the master branch. If things don't go so well you can always discard the branch or keep it within your local repository.

How do I add a comment to a git commit?

Another method of adding a multi-line Git commit message is using quotes with your message, though it depends on your shell's capacity. To do this, add single or double quotes before typing the message, keep pressing enter and writing the next line, and finally close the quote at end of the message.

What command allows you to create new branches or see information on existing branches?

The git branch command lets you create, list, rename, and delete branches.


1 Answers

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 merge.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.

like image 83
Christopher Avatar answered Sep 23 '22 06:09

Christopher