DEV Community

Gaute Meek Olsen
Gaute Meek Olsen

Posted on • Updated on • Originally published at gaute.dev

git commit -a

Today I learned that you can add -a to a commit command to automatically stage files that have been modified and deleted.

Why write two lines:

git add .
git commit -m "msg"
Enter fullscreen mode Exit fullscreen mode

When you can write one:

git commit -m "msg" -a
Enter fullscreen mode Exit fullscreen mode

NB: new files you have not told Git about are not affected.

Top comments (5)

Collapse
 
pavelloz profile image
Paweł Kowalski

Or even shorter, git commit -am "msg" ;)

Collapse
 
gautemeekolsen profile image
Gaute Meek Olsen

Nice! Thank you, that is one hyphen and one space I am happy to get rid of :D

Collapse
 
rsolci profile image
Rafael Solci

Although its a nice command, I prefer using git add -p first, so I can review each modification and decide whether to stage it or not.
I'ts one step more for sure, but saved me of commiting unecessary changes

Collapse
 
gautemeekolsen profile image
Gaute Meek Olsen

Lovely! I didn't know about the -p flag. Definitely going to use this one from time to time. Thank you.

Collapse
 
terkwood profile image
Felix Terkhorn

Good point! 🌟