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 Branches Beginning to Branch

kabir k
PLUS
kabir k
Courses Plus Student 18,036 Points

git commit -m “some comment” vs. git commit -a -m “some comment”

What's the difference between these two commands?

git commit -m “some comment”

and

git commit -a -m “some comment”

I'm trying to be clear on this.

my understanding is that -a adds all of the un-added files to the staging area before you commit them. Otherwise it would be a two step process.

2 Answers

Seth Kroger
Seth Kroger
56,413 Points

The -a flag will add any files modified since the last commit to the staging area right before the commit. It allows you to combine the "git add" with "git commit" into one command. It won't add new files you've created though. For those you need to use git add to add them to the staging area.

kabir k
kabir k
Courses Plus Student 18,036 Points

Hey Seth,

I thought the -a option stands for "all" and that git commit -m "some comment" is used to commit a version of your code into the repository?

Kareem Jeiroudi
Kareem Jeiroudi
14,984 Points

git commit -a will automatically add all modified files in the repository to the staging area AND commit them too, which means with this command you can skip the adding (git add <fileName>). However, git commit commits only files that are explicitly added to the staging area. I hope that was helpful.