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

kofi amoussou
PLUS
kofi amoussou
Courses Plus Student 7,381 Points

whats the difference between git commit -a -m and git commit -m cant seem to wrap my head around it

whats the difference between git commit -a -m and git commit -m cant seem to wrap my head around it. i thought git commit -a was to commit all changes but in the task challenge i sometimes get an error when using the first and it accepts the latter

1 Answer

Hi there kofi.

Well the short way to explain: if you use git commit -a than automatic staging is made so that you don't need to use git add before committing. Initial add must be made so that you initialize file tracking but then you just commit the changes.

If you add a new file into the repo than you have to use git add to start tracking the file and then you can use the -a flag when committing.

Check this LINK to get the full info about the flag.

The -m flag is used like this: git commit -m "Message" <- which means you are writing a comment on the command line using double quotes string

If you omit the -m flag a text editor will open and ask you to add a comment.

Just try with and without the -m flag to see the difference.

Happy Coding!!!