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

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Marking Todo Items Complete

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

Before committing, adding our work twice?

In the video "Marking Todo Items Complete" (8:20), I thought a in -am stands for add, why are we adding our work twice, before committing them?

Here are the commands in question for adding our work,

treehouse:~/projects/odot (master *) $ git add .
treehouse:~/projects/odot (master +) $ git commit -am "Mark todo item as complete"

1 Answer

Kevin Korte
Kevin Korte
28,149 Points

There is a bit of a difference.

Adding the -a flag to the commit causes git to stage every file already tracked. This would not include new files that have not already been tracked.

git add . stages already tracked files, and tracks modification to new files, and adds new files in. It does not stage any deleted files though.

So, in laymen terms,

Git stage new and modified files, without deleted git commit all staged files.

It is a bit redundant, but it is what it is. You this case, if you would have just ran git commit -am you would have committed all files already tracked, but not commited any untracked (i.e. new files), which might be helpful at some point.

I'd encourage you to read about the different git add -A, git add ., git add -u, etc options, I really think this answer does a good job.

http://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add

This is a bit more dry, but it's official docs, and very thorough : https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository