Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,842 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,842 Points

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