git status shows the current state of your Git working directory and staging area.
What Does git status Do?
A useful feature of git status is that it will provide helpful information depending on your current situation. In general, you can count on it to tell you:
- Where
HEADis pointing, whether that is a branch or a commit (this is where you are “checked out” to) - If you have any changed files in your current directory that have not yet been committed
- If changed files are staged or not
- If your current local branch is linked to a remote branch, then
git statuswill tell you if your local branch is behind or ahead by any commits
During merge conflicts,
git status will also tell you exactly which files are the source of the conflict.How to Use git status
Common usages and options for git status
git status: Most often used in its default form, this shows a good base of informationgit status -s: Give output in short formatgit status -v: Shows more “verbose” detail including the textual changes of any uncommitted files
Example Output
When you rungit status, you might see output like this:
When to Use git status
Before Committing
Always rungit status before committing to ensure:
- You’re on the correct branch
- You know which files are staged
- You understand what will be included in your commit
After Making Changes
After editing files, usegit status to see:
- Which files have been modified
- Which files are untracked (new files)
- Which files are staged for commit
Before Pushing
Before pushing to a remote, checkgit status to:
- Confirm you’re on the right branch
- See if your branch is ahead of the remote
- Ensure all changes are committed
During Merge Conflicts
During a merge conflict,git status will show you:
- Which files have conflicts
- Which files have been resolved
- What stage you’re at in the merge process
Understanding the Output
Branch Information
git status always starts by telling you which branch you’re on:
Tracking Information
If your branch tracks a remote branch, you’ll see:File States
Files can be in different states:- Untracked: New files that Git isn’t tracking yet
- Modified: Changed files that aren’t staged
- Staged: Files ready to be committed
- Unmerged: Files with merge conflicts
Related Commands
git clone [url]: Clone (download) a repository that already exists on GitHub, including all of the files, branches, and commitsgit remote -v: Show the associated remote repositories and their stored name, likeorigingit remote add origin <url>: Add a remote so you can collaborate with others on a newly initialized repositorygit push: Uploads all local branch commits to the remotegit push -u origin main: When pushing a branch for the first time, this type of push will configure the relationship between the remote and your local repository
Next Steps
Git Add
Stage files shown in git status
Git Commit
Commit your staged changes
Git Push
Push your commits to the remote
Git Pull
Update your local branch