Last Updated: May 30, 2016
· mislav

Keep TODOs in git

You can keep quick, short-lived personal TODOs as empty commits in the current git branch (original tweet):

todo() {
  git commit --allow-empty -m "TODO: $*"

<i>You can save this either as a shell function or git-todo executable.</i>

Use it like so from the command line:

todo Check if feature X works under edge-case

This records an empty commit prefixed with "TODO". This way git log will remind you both what you have done on this branch and what you need to be doing:

$ git log --oneline master..
9ca4a06 TODO: Check if feature X works under edge-case
ca343b0 implemented awesometastic feature X

Obviously, these commits are only meant to be temporary and never part of the long-term project history. If you're doing your housekeeping and git rebase -i the branch every time before you push, git notices that these TODO commits are empty and automatically comments them out from the list of commits to keep.

pick ca343b0 implemented awesometastic feature X
# 9ca4a06 TODO: Check if feature X works under edge-case
fixup 5c33289 fixed the edge case

You still get to review the TODO list, but you don't have to worry about cleaning up these commits manually.

This isn't a mechanism to store long-term TODO items or share them with the rest of your team. It's more for adding reminders to yourself for your next coding session.

7 Responses
Add your response


Because you recommend doing this on feature branches it might be useful to only see the log since the dev branch, you can also do a grep for the word 'TODO'.

git log origin/dev..HEAD --grep=TODO: --oneline
over 1 year ago ·

This seems like a fairly complicated and error-prone solution to a problem with many other viable solutions. Is this just really specific to your workflow? What made you want to take this route?

over 1 year ago ·

@mustardhamsters: Yes, I have the same question. Do you really use this for your current workflow ?
Because normally we have github which is quite good to track issues. This is really fun but I don't like the idea of putting TODO in code, neither in VCS :)

over 1 year ago ·

@mustardhamsters I don't find this complicated. It's a shell one-liner that you invoke with a single keyword, and git rebase -i should already be a part of your workflow regardless.

But I do understand your concern. This isn't a strong solution for storing long-term TODOs, and I should have stressed that out. It's just a silly hack to store quick TODOs for yourself as you're hacking away on a topic branch. Yes, I use this for myself, but for long-term TODOs I as well use a local todo.txt file or GH issues. I'll amend the text above.

over 1 year ago ·

Don't like that solution. IMHO better is using in-code TODOs and my git todo alias, external TODO file or use git notes.

over 1 year ago ·

Apologies if I'm double-posting this. My previous comment seems to have been lost.

I've adopted a variant of your todo commit:

todo() {
  git checkout -b $1
  git commit --allow-empty -m "TODO: $2"
  git checkout -


todo fix-foobar "Fix foobar"

This creates a new branch 'fix-foobar' based on your current branch, switches to it, creates an empty commit with message 'Fix foobar', and switches back to your original branch.

In other words, it puts a todo commit in its own branch, out of the way of your regular work. If you then decide to fix foobar, you can checkout 'fix-foobar', commit as necessary, and do a simple rebase. The original empty commit will be automatically squashed out of existence.

So it's a natural way to create and defer working on feature branches.

Thanks for the original idea.

over 1 year ago ·

I use twig (gem) for add notes to branches like this:

twig todo "Fix: refactorign"

And looks like this:

➜  rest-in-peace git:(develop) twig

                                     todo                branch
                                     ----                ------
2013-09-04 19:39 -0400 (hace 5 d...  FIX: refactoring  * develop

If you want to know and branch's attribute:

➜  rest-in-peace git:(develop) twig todo
FIX: refactoring

To install twig (I use rvm):

$ gem install twig
over 1 year ago ·
Filed Under