Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Development Tools Git Basics Working With Remote Repositories Pushing and Pulling

Ahmed Abdelaal
Ahmed Abdelaal
6,328 Points

committing

Throughout the video, I've seen that Tommy just committed after editing file2 twice and once after editing file1. He just went ahead with committing though without adding the files to the staging area. This just threw me off a bit so any explanation would be much appreciated!

3 Answers

Stone Preston
Stone Preston
42,016 Points

did he add all the files to the staging area at the beginning maybe using

git add -A 

then commit?

Ahmed Abdelaal
Ahmed Abdelaal
6,328 Points

He edited the same file twice. The first time he used nano to edit the files and the next line of code was straight into a commit.

$ nano file2 $ git commit -a -m "Edit file2 some more

the second time he used

$ git nano file2 $ git add file 2 $ git commit

what threw me off is that he edited the same file twice using nano but once without staging and then second time he did.

so if I include -a in my commit then I shouldn't have to stage the files?

Stone Preston
Stone Preston
42,016 Points

yes. that will add it to the staging area then commit it, all in one line.

Stone Preston
Stone Preston
42,016 Points

just note that the one line method will only work if the file is already being tracked in the repo. If its a new file that has yet to be added you have to do it using git add, then commit.

Stone Preston
Stone Preston
42,016 Points

And that using -a adds the current version of all the files in the branch, not a specific file