git status command can be a helpful tool when you need to know what state your local repository is in with respect to the remote repository.
Some basic terms to be familiar with as we go forward:
Local Repository – This is your local version of your project on your machine. It will have a repository that is connected to a repository in your version control (GitLab, GitHub, etc).
Remote Repository – This is the version of your project that is checked into your version control program of choice. This can include GitHub, Gitlab, Bitbucket, etc. You can check which remote repository you are using for fetching and pushing by typing
git remote --v in your terminal in the local git repo directory.
- Career Karma matches you with top tech bootcamps
- Get exclusive scholarships and prep courses
Open a terminal in the root of your local git repository. Type
git status and press enter.
The following is a list of responses you might get after running
Up-To-Date, Working Directory Clean
The first half tells us you have nothing to push to your remote repository. Your local repo matches your remote repo.
The second half says there are no more commits that are needed to be made. Every change has been staged and committed – your working tree or directory is clean.
Your local repo doesn’t match what your remote repo has. The “ahead by 1 commit” means your local repository has more changes that have not made it up to the remote repository.
The untracked files are the files that have not been checked into version control. Use
git add to check them into staging.
The last message talks about whether or not you have added/commited your files to push to your remote repository. If your working directory is clean, it will say so and you’re ready to push to your remote repo.
Changes not staged for commit
In this situation, the file
app.js was previously added to git and is maintained under version control. Follow the directions here to add or discard the changes that were made to the file(s). The command
git commit -am “<Meaningful commit message here>” will add and commit the file at the same time.
Changes to be committed
If you see this message, it means you have previously run
git add to stage your changes, but you have not run
git commit. To fix this, run
git commit -m “<Meaningful commit message here>”. If you would like to undo the staging and move the files out of the staging area, use
git reset HEAD.
Your branch is ahead of ‘origin/master’ by <x> commits
All of your changes have been added and committed. You are ready to push the changes to your remote repository.
This means that you have a merge conflict. A merge conflict means that a file on your remote repository has been modified and then that same file also has been modified on your local repository. You don’t yet have the updated code from the remote repository, but there have been local changes made.
Check out the Career Karma article on how to resolve merge conflicts to see the different ways to fix this message.
Not a Git Repository
If you get this message, it means the directory you are in is not a git repository. Double check that you are in your project’s root folder and that it has a
.git folder associated with it.
To check that you will need to run
ls -a. This will show you all of the files and folders in your root directory, including those that are hidden.
If you have a
.git folder in your list, you know that you have initialized a git repository. If there is not a
.git folder there, run
git init to initialize your folder as a git repository.
git status is helpful when we need to know or keep track of changes that have been made to our local repository as they relate to our remote repository.
This is super helpful when you are newer to git and are still learning the commands to use it in the terminal as it gives hints on what you need to do to continue to push changes to your remote repository.
Once you have learned the basics of how
git status works for files tracked by git, check out the git-status docs to learn more about options you can use along with the
git status command.
About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.