Tracking Changes
Tracking changes is the whole point of git, but in order to understand how they're processed, you must understand what the Working Tree and the Staging Area are.
Learning Objectives
- Understand what the Working Tree is
- Understand what the Staging Area is
The Working Tree is the repo where git is initialised, with all of its files and subdirectories. Think about it as a box, where you store everything related to your project. You can check your working tree with:
Which shows all of your untracked files. Even though git is initialised, and it's tracking your changes, you still need an extra step to fully use its capabilities.
You can add specific files to what we call the staging area, by running the command:
Or you can add them all at once:
If you add a file to the staging area by mistake, you can always remove it with:
Once you have some files in the staging area, you'll have to commit them. Your commit should also have a commit message which states the changes you made to the file, so anyone reviewing the code or using it after you understands what this commit is about. You can do so by running:
Finally, you want to push those committed files to your remote repo. The first thing to do is to check if the remote one is connected to your local one:
If it is connected then your output should look something like:
If not, you can connect them with:
All you need to do is: