Git is the most popular version control system which records the changes made to our project over time in a special database called a repository. We can look at our project and see who has made what changes when and why and if we screw something up we can easily revert our project back to an earlier state.
Below are pre-requisite git commands one should be well aware of that are as follows:
Git init: The git init command is used to initialize the git into the existing project. By using this command we can convert the normal project folder into a git repository.
$ git init
Git add: The git add command is used to place the modified version of the working directory in the staging area.
$ git add <file-name> or git add .
Git commit: The git commit command is used to commit the modified files which are available in the staging area.
$ git commit -m "Commit Message"
Git Status
The git status command is used to show the status of the git repository. This command displays the state of the local directory and the staging area.
$ git status
Creating project folder and Initializing Git
$ mkdir gfg
$ cd gfg
$ git init
Output:

Git Status when working tree is clean:
$ git status
Output:

Here, the Working tree is clean that’s why the output is coming as nothing to commit.
Git Status when a new file is created:
$ touch new.txt
$ git status
Output:

Here, We created a new file that’s why it is showing untracked files. We can use the ‘git add’ command to include this file.
$ git add new.txt
$ git status
Output:

Now, It is showing changes to be committed which means the file is now included and ready to commit. We can commit files using the git commit -m “message” command.
$ git commit -m "first commit"
$ git status
Output:

After committing, the status is now changed to nothing to commit because now the working tree is clean.
Git Status when an existing file is modified:
First, we need to add some content to our new.txt file.

Now execute command i.e.
$ git status
Output:

It is showing modified: new.txt means something is modified in it. Now let’s add it and commit it.
$ git add new.txt
$ git commit -m "file modified"
$ git status
Output:

After adding and committing our working tree is cleaned that’s why git status is showing ‘nothing to commit’.
Git Status when the file is deleted:
$ git rm new.txt
$ git status
Output:

After deleting the file git status command show’s the deleted file name and it is also ready to commit it by using the git commit command. So let’s commit it and then see the status of the repo.
$ git commit -m "file deleted"
$ git status
Output:

After committing our working tree is cleaned that’s why git status is showing ‘nothing to commit‘.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
15 Mar, 2022
Like Article
Save Article