Staging Area

Why is the staging area really needed?
Is it because git is a distributed version control system?

What is the advantage to stage a file and not to commit it?
If my computer crashes, i would still loose the contents of the staged file, no?

If i understand right the files which we can recuperate and track (version history) are only the ones which were commited, no?

thanks for the hints

The staging area, or index, represents one of the three core components of a git repository, namely:

  • the working tree, containing the files you can edit;
  • the index, containing the proposed next commit;
  • the repository database, containing the history.

Therefore, the index acts as a mere container to let you group up all the changes that are going to populate the next commit. All this editing might happen at once or incrementally over time, throughout the steps you planned to do.

I usually follow the former strategy, where I edit my files in the working tree and only then I stage + commit them at once. People may be in favor of filling in the index incrementally, instead, in order to introduce a further level of tidiness in their work.

That said, it comes out that:

  • The presence of the index is not related to the distributed nature of Git.
  • In the unfortunate event of an irrevocable crash, you would lose your staged modifications along with all the content you have not backed up elsewhere. Indeed, you would lose your edits also in case you committed them earlier since only commits pushed to a remote repository are preserved.

Hello Ugo

Thanks for the hints and explanations!

I used to work with TempoSync, and then SVN.

And therefore still needing to understand the small differences among these and git.

Next step now, is to get more about ways to use GitHub Education in my courses (:o)