C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Git StatusThe git status command is used to display the state of the repository and staging area. It allows us to see the tracked, untracked files and changes. This command will not show any commit records or information. Mostly, it is used to display the state between Git Add and Git commit command. We can check whether the changes and files are tracked or not. Let's understand the different states of status command. Status when Working Tree is cleanedBefore starting with git status command, let's see how the git status looks like when there are no changes made. To check the status, open the git bash, and run the status command on your desired directory. It will run as follows: $ git status Output: Since there is nothing to track or untrack in the working tree, so the output is showing as the working tree is clean. Status when a new file is createdWhen we create a file in the repository, the state of the repository changes. Let's create a file using the touch command. Now, check the status using the status command. Consider the below output: As we can see from the above output, the status is showing as "nothing added to commit but untracked files present (use "git add" to track)". The status command also displays the suggestions. As in the above output, it is suggesting to use the add command to track the file. Let's track the file and will see the status after adding a file to the repository. To track the file, run the add command. Consider the below output: From the above output, we can see that the status after staging the file is showing as "changes to be committed". Before committing blindly, we can check the status. This command will help us to avoid the changes that we don't want to commit. Let's commit it and then check the status. Consider the below output: We can see that the current status after committing the file is clean as it was before. Status when an existing file is modifiedLet's check the status when an existing file is modified. To modify file, run the echo command as follows: $ echo "Text"> Filename The above command will add the text to the specified file, now check the status of the repository. Consider the below output: We can see that the updated file is displayed as untracked files. It is shown in red color because it is not staged yet. When it will stage, its color will change to Green. Consider the below output: Status when a file is deletedLet's check the status when a file is deleted from the repository. To delete a file from the repository, run the rm command as follows: $ git rm < File Name> The above command will delete the specified file from the repository. Now, check the status of the repository. Consider the below output: The current status of the repository has been updated as deleted.
Next TopicGit Branch
|