Search code examples
gitstaging

Concept of git tracking and git staging


When you modify a file in your working directory, git tells you to use "git add" to stage.

When you add a new file to your working directory, git tells you to use "git add" to start tracking.

I am a bit confused about these 2 concepts because i assumed tracking a file for changes is different from staging it for commit


Solution

  • Git has a concept known as 'the index'. To create a new commit, you fill the index with the contents you'd like to have in the next commit. That means that you have to explicitly tell Git which changes you want to appear in the next commit by using git add. (git add -p to add only single hunks)

    It doesn't make a difference to Git whether you only update a file (»stage changes«) or if you add the full content of a new file (»start tracking a file«) – both times, all that Git's index sees is the addition of new changes