git status provides detailed information about the working directory (where your code is stored on your local machine) and the index (the staging area where your changes live before being pushed to a remote repository). This command will show you:
- Which changes have been staged for commit.
- Which changes are in the working directory but not yet staged for commit.
- Which files are not being tracked by Git.
When you run git status, Git categorizes files into several sections:
- Changes to be committed: These are changes that have been added to the staging area with
git addand are ready to be committed to your repository. - Changes not staged for commit: Changes in files that are tracked by Git but have not been added to the staging area yet.
- Untracked files: Files in your working directory that are not being tracked by Git. These are usually new files that have been added to your project, or files explicitly ignored by Git specified in the .gitignore file.
Using git status
To use the git status command, run:
git status
Example 1: A clean working directory
After committing all your changes, if there are no untracked or modified files, git status will show:
On branch mainYour branch is up to date with 'origin/main'.nothing to commit, working tree clean
This output indicates that your working directory is clean and there are no changes to commit.
On branch main: This indicates that you are currently on the
mainbranch of your repository. In most Git repositories,main(ormasterin older repositories) serves as the primary branch where the final version of your project lives. This is where all the development branches are eventually merged back into.Your branch is up to date with 'origin/main': This tells you that your local
mainbranch is synchronized with themainbranch on the remote repository (usually namedorigin). "Up to date" means that there are no commits on the remote branch that you don't have locally, and there are no local commits that haven't been pushed to the remote. Essentially, both your local and remote repositories are in the same state in terms of commit history. Due to the way remote branches are tracked, you may need to rungit fetchto fetch the most up-to-date changes from the remote repo. There may be remote changes that your local copy of the remote repository doesn't have yet.nothing to commit, working tree clean: This message is quite straightforward. "Nothing to commit" means that there are no changes in your repository that need to be committed. In other words, if you've made changes to your files, they have all been staged (with
git add) and committed (withgit commit). The "working tree clean" part indicates that there are no modified or untracked files in your current directory. The "working tree" refers to the set of files and directories in your current project that Git is tracking. This message confirms that all changes have been committed to the repository, and there are no pending changes or files that Git is not tracking.
Example 2: untracked files
If you have just added a new file to your project and haven't staged it yet:
On branch mainYour branch is up to date with 'origin/main'.Untracked files:(use "git add <file>..." to include in what will be committed)newfile.txtnothing added to commit but untracked files present (use "git add" to track)
This tells you that newfile.txt is not being tracked by Git. You can stage it for commit with git add newfile.txt.
Example 3: changes not staged for commit
After modifying a file, if you run git status before staging it:
On branch mainYour branch is up to date with 'origin/main'.Changes not staged for commit:(use "git add <file>..." to update what will be committed)(use "git restore <file>..." to discard changes in working directory)modified: modifiedfile.txt
This output shows that modifiedfile.txt has changes that have not been staged for commit.
Example 4: Changes staged for commit
Once you stage the changes with git add, running git status again will output:
On branch mainYour branch is up to date with 'origin/main'.Changes to be committed:(use "git restore --staged <file>..." to unstage)modified: modifiedfile.txt
Now, modifiedfile.txt is ready to be committed.
For further reading about the git status command see the official Git documentation.