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!

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

Why was the -a flag needed?

Why does he use the -a flag, when he had already staged README.md and there are no other files that need to be staged?



2 Answers

Jason Anders
Jason Anders
Treehouse Moderator 145,840 Points

I interpreted it as just a good habit to get into. Kind of like hitting 'save all' when working in Photoshop or Text Editors... just in case there was something you were working on that you forgot you changed.

Sean T. Unwin
Sean T. Unwin
28,688 Points

git add will add files to the index (the list of files being tracked for the repository). This does not add files to the commit, it only adds to the list of files which are able to be committed.

git commit -a will include all (that's what the 'a' stands for) files in the index (the files being tracked) to the commit. This will include any modified files in the index as well as remove any files which have been deleted from the index.

Thanks for your reply Sean!

To me it just seems unnecessary in this particular scenario, as he has already staged README.MD, would I be right in assuming that the "-a" flag was not necessary in this scenario, but more so good practice?

I've read up on the difference between "git commit" & "git commit -a"

"git commit -A" Ensures even file deletions are included. By 'Included' does that mean, the deleted files are included in the repository?

Cheers :) Seb