Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Git Basics Getting Started With Git Looking Back on What We've Done

Mathew Kurian
Mathew Kurian
4,698 Points

What's the difference between "git commit" and "git commit -a"?

I know that "git commit -a" tells git to commit all the changes that it finds. But what does git commit do by itself then?

Say I created 3 new files and then ran "git commit -a". Does this effectively act like a "git add" for each of the three files, and then a "git commit" command? In this case, what would happen if I just wrote "git commit"? Would I have to add all the files first?

1 Answer

Chris Shaw
Chris Shaw
26,676 Points

Hi Matthew,

You nailed it, nice one. As you already said git commit would first require you to add files to be staged otherwise when you go to commit your changes you'll get a message saying nothing to commit.

One other thing to note is if you have no need to worry about adding all files upon every commit, you can also join the commit message itself onto git commit -a using the m flag and passing a message within quotes.

git commit -am 'message here'

Happy coding and well done on getting your bearings with git. :smile: