News Stay informed about the latest enterprise technology news and product updates.

How to master the Git status command

If distributed version control is your thing, you need to master the intricacies of the files on your working tree, and that means you must learn the Git status commands and understand the information it can provide.

The goal of the Git status command is to provide you information about the state of the various files in your working directory, also known as the working tree. The six different states the Git status command can inform you of are:

  1. There is no commit history
  2. There are untracked files
  3. There are changes to be committed
  4. The working tree is clean
  5. Files have been modified
  6. Files have been deleted

How to use the Git status command

To really learn how to use the Git status command, follow these steps:

  1. Issue a git init command to create a new repository
  2. Issue the git status command and note the results
  3. Add a new file named index.html to the repository
  4. Issue the git status command and inspect the results
  5. Issue a git add . command
  6. Run the git status command and note the results
  7. Issue a Git commit
  8. Run the git status command and inspect the results
  9. Modify the index.html file
  10. View the results of the git status command
  11. Delete the index.html file
  12. Inspect the results of the git status command

Going through this cycle of git status commands will demonstrate each of the states the tool will report upon.

Nothing to commit status

When a new repository is created, the git status command reports there is nothing to commit:

$ git init
Initialized empty Git repository in C:/_bart/.git/

$ git status
On branch feature No commits yet
nothing to commit (create/copy files and use "git add" to track)

Untracked git status

When new files are added to a repository, git status reports untracked files

$ touch index.html

$ git status
On branch feature No commits yet
Untracked files:
    index.html
    nothing added to commit but untracked files present (use "git add" to track)

Changes to be committed git status

When new files are added to the index, the git status reports changes to be committed:

$ git add index.html

$ git status
On branch feature No commits yet
Changes to be committed:
    (use "git rm --cached <file>..." to unstage)
    new file:   index.html
git status command example

This git status command example will help you understand the various states of files under version control

Clean working tree status

After a commit, the git status will report a clean working tree. This can also be triggered by running a git clean command:

$ git commit -m "Git status and working tree commit"
[feature (root-commit) 1159b26] Git status and working tree commit
  1 file changed, 0 insertions(+), 0 deletions(-)
  create mode 134221 index.html
$ git status
On branch feature
nothing to commit, working tree clean

Modified git status

If a file is edited the status reported will be modified:

$ echo "Hello World" >> index.html

$ git status
On branch feature
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
    modified:   index.html
    no changes added to commit (use "git add" and/or "git commit -a")

And finally, if you remove a file, the git status will report that a file has been deleted:

$ rm index.html

$ git status
On branch feature Changes not staged for commit:
   (use "git add/rm <file>..." to update what will be committed)
   (use "git checkout -- <file>..." to discard changes in working directory)
      deleted:    index.html

And those are the ‘ins and outs’ of the git status command. Learn these various different statuses, and you will be a master of the command.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

SearchAppArchitecture

SearchSoftwareQuality

SearchCloudComputing

SearchSecurity

SearchAWS

Close