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 Looking Back on What We've Done

Maksims Visnakovs
Maksims Visnakovs
2,616 Points

Staging our changes

Hi community,

I have a question about commiting changes. I understand that if you commit change one by one you use 'git add' first and after you added the change you commit it straight after and if you want to commit all the changes at once you type in command 'git commit -a". So now i am confused, after I have done a task 'Staging our changes" when the task asked to commit all the changes I typed in "git commit -a -m "Commiting changes in README and prototype"" and it didn't work. Then I tried to type in 'git commit -m "Commiting all changes"" and it worked. But surely this command should commit only the last one, or am I missing something? Please, someone clarify that to me.

Kind Regards,

Maks

2 Answers

Sergey Podgornyy
Sergey Podgornyy
20,660 Points
  • You prepare all files for commit using git add .
  • For commit your project type git commit -m "first commit"

When you type git commit -a -m "first commit" , you commit your changes without preparation

Thank you! this is very important to know. I had exactly the same doubt.

Sergey is right but just one last point: When you type git commit -a -m "first commit" , so when you use the-a flag, you commit all changes on files that are inside and outside of the staging area, so ALL files. So you commit the ones not staged to be committed (not in the staging area) and the ones with changes to be committed (staging area) .

Without the -a flag you commit only the ones that are inside the staging area.