Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

  • Blog Navigation
git unadd

Sometimes I accidentally git add files. Or more often, I do git add . and get a huge changelist and then realize I want to move certain files to a different changelist or a different branch. I could do a git reset which, absent --soft or --hard, pulls all the changes out of the index (aka dircache aka staging area) but leaves them in the filesystem (aka working tree). But wouldn’t it be nice to leave all the files in the index except the few I want to keep out?

Yes. Yes, it would. And believe it or not, git has been telling you how, every time you do a git status. Like me, you’ve probably seen this line often enough for it to be completely invisible:

#   (use "git reset HEAD <file>..." to unstage)

“Oh,” I hear the whole Internet saying, “that’s what that means.

“But why,” you continue, “instead of
documenting an obscure feature at runtime during a tangentially related operation, wouldn’t they just provide a simple git unadd command?”

Fortunately, you can just run

git config --global alias.unadd "reset HEAD"

and now you can do

git unadd foo.txt bar.txt

and only those files will be pulled out of your index. (Unfortunately, the silly overcommunication is not removed this time.)

  1. Alex Chaffee says:

    See also GitFaq: [Why is “git rm” not the inverse of “git add”?](

  2. Sebastian says:

    Any particular reason you didn’t go for “remove”? “unadd” seems almost as obscure as “reset HEAD”.

  3. Alex Chaffee says:

    “remove” is an expansion of “rm” and means something else altogether in Gitistan — see that FAQ link in my earlier comment. I agree that git terminology is hazy at best but I’m not in a position to fix it, and after [browsing Google]( it seems many others share my intuition that you’d call undoing an add an “[unadd](”.

  4. Tom Ward says:

    Nice little trick, now added to my aliases. Thanks for sharing.

  5. Thanks, this is useful… Now I’m worried my custom git configs might end up as long ad my vim config!

  6. Jack Dempsey says:

    Cool stuff Alex. For those who may not know, HEAD is the default:

    Commit to make the current HEAD. If not given defaults to HEAD.”

    So, its really just typing unadd instead of reset. I can see how that will work nicely and all, but sometimes I find myself in a land without personal aliases and wishing I hadn’t used so many. ymmv.

  7. Mark Wilden says:

    Even when I’m on a system without all my pretty aliases, it’s useful to know that git is case-insensitive by default, so you can type ‘head’ instead of ‘HEAD’.

  8. Pieter says:

    added alias. thanks :)

  9. yolanda says:

    Awesome I learned 3 things :

    – How to unadd something

    – How to alias stuff

    – To read the messages git tells me!

    Note that if this is the initial commit, there is no HEAD. So git reset HEAD doesnt work. Instead, you have to do : git rm –cached …

    But again… git told me that… and I couldnt see it….

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *

Share This