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 Committing Changes

When to use -a in commit?

When should I use -a in commit and when i should not use it?

In other words, what is the difference between:

git commit -a -m "comment"

and

git commit -m "comment"

2 Answers

Michael Hulet
Michael Hulet
47,913 Points

The -a flag tells git to commit all the changes it finds. It essentially allows you to skip ever running git add

Mathew Kurian
Mathew Kurian
4,698 Points

I had this same question also. So if you create 5 new files and then run "git commit", does it just add all the files?

Michael Hulet
Michael Hulet
47,913 Points

Running git commit without staging anything will do nothing. You must either run git add first, or run git commit -a instead