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 The Staging Area

What is the Staging Area in Laymen's Terms?

I didn't understand the copy/paste answer located here: https://teamtreehouse.com/community/what-is-staging-area

Specifically:

1) Is the Git directory the local directory on your computer?

2) I'm assuming the directory is located within that hidden .git file within your project file folder?

3) How does the staging area differ from a commit, as it appears both save a copy of the file?

4) Wouldn't the staging area also continue to store your changes locally(?) regardless of whether we commit or not?

5) Why do we need to go through this 2 step process in order to save a copy of your project to Git? (stage & then commit) Either the staging area or the commit seems redundant...

Thanks for elaborating!

1 Answer

Charles Dunn
Charles Dunn
5,817 Points

I'll do my best to answer your questions...

1) When you create a new directory for a project and you run the git init command you are creating a hidden .git directory within your new project directory. This hidden git directory will track all your project files. So yes, the .git directory is stored locally on your computer.

2) The .git directory is stored within your project directory. If you run the command ls -a it will show you all the hidden files and directories.

3) The commit creates a snapshot of your file in its current state. The staging area allows you to "prepare" your file for a commit. I like to think of it as a double check opportunity. You can easily remove files from the staging area and make more changes, but you should think of a commit as permanent (even though it is possible to delete one).

4) The version of the file in the staging area will not be updated with any changes made to the file after it's been added to the staging area. In other words, if you makes some changes, add the file to the staging area, then make more changes, the second round of changes won't be reflected. You would either need to 1) commit the current version and then re-stage the file and commit the second round of changes or 2) pull the file out of the staging area, then re-add it and commit all the changes at once.

5) I can see how it seems a little redundant, but it's basically a way for you to mark a file that you've modified before you actually create a "concrete" snapshot of it. You can use the command "git add ." to add all modified files to staging to speed things up, but just be aware that you might be adding something that you didn't intend to commit eventually.

Hope this helps!