Hurry! Try our new Interactive Courses for FREE. 🥳   🚀

GIT: The Staging Area

Till now, we've either been adding just one file to the repository or multiple files at once. What if we want to control what we commit to our repository? As mentioned earlier, Git provides us with a Staging Area that makes controlling our commits easier. First things first, make sure that you have returned to our awesome project repository.

Now, run the following command on your terminal: $ git status

As you may have guessed, this command will give out the status of that repository. The output seems pretty boring right now.

Notice the 'working directory clean' statement. In other words, there are no tracked and modified files. Git also doesn't see any untracked files, or they would be listed here. Finally, the command tells you which branch you're on and informs you that it has not diverged from the same branch on the server. For now, that branch is always "master", which is the default; you won't worry about it here.

But we've added the README file to our repository and there seems to be no sign of it in the status.

Git status will only show files with some special status assigned to them. Since the commit of the README file, there have been no modifications to it. Hence, the status of that file is not important to it as of now. If it showed status of all files in the repository, it would be a long and tedious task when you are working on a big project.

Our project directory is somewhat empty, containing only the README file. Go ahead and create some files (empty ones will do). Run the status command again to see if anything exciting is waiting for us!

Staging Area in GIT

Indeed there is! Notice that we did not get the 'working directory clean' message this time, can you guess why?

Right! We added some new files to the project which haven't been added to the repository yet. Go on and add file1 to repository (recall that we can use the git add command). Running the status command again will give out a new message this time. Things are getting exciting!

Staging Area in GIT

Now, you can either commit this file or add file2 & file3 to the repository and then commit all of them together. Before we move on, open up the files in an editor and add some content to them. When you check the status again, Git explicitly tells you that these files have been modified. This feature helps you keep your cool when working with larger projects.

Staging Area in GIT

Try creating some more files and look around for yourself! In the next chapter we shall look into more Git basics. Let's go!