When you have added all of the changes in a repository to a commit, the Git command line will classify your working directory as “clean”. You’ll see this description if you run git status
to check the status of your repository.
In this guide, we’re going to discuss what the “nothing to commit, working directory clean” message means. We’ll also discuss why you see this message even when you have made changes to your local repository that have not been pushed to a remote repository.
nothing to commit, working directory clean
Git is a distributed version control system. This means you can maintain multiple separate copies of a repository.
Because multiple copies of a repository can exist, different developers can work on their own version of a repository locally. Then, when they have finished making a change, they can push their changes to the main version of the repository.
The “nothing to commit, working directory clean” message tells us all of the changes we have made to a Git repository are committed. This means the current state of our project folder is exactly the same as that of the last commit.
When you add, remove, or delete a file, this message will change. You’ll see a list of the files you have changed and a description of whether you have created, modified, or deleted that file.
Let’s run the git status command on a repository to which we have made no changes:
On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean
The git status command tells us we are viewing the “master” branch. The command also tells us we have not made any changes to our repository since the last commit.
If you have set up your project with a remote, you should see a message telling you whether all of the changes you have made to your repository have been pushed to the remote. This is the “Your branch is up to date” message above.
nothing to commit, working directory clean Error
The “nothing to commit, working directory clean” message may appear in error. This happens if you have not set a branch on your repository upstream.
Let’s create a local copy of our demo Git repository, ck-git. To start, we’re going to initialize a new repository, add that repository as a remote, and pull the contents of the repo:
git init git remote add origin https://github.com/career-karma-tutorials/ck-git git pull origin master
These commands retrieve the code from the career-karma-tutorials/ck-git repository on GitHub. Next, let’s modify a file and add it to a commit:
echo "This project is a work in progress." >> README.md git add README.md git commit -m "docs: Add work in progress notice"
We have just added a line of text to the README.md file. Then, we added the README.md file into the staging area and all the files in the staging area to a commit.
Let’s run git status to make sure our changes have been made:
On branch master nothing to commit, working tree clean
This command tells us that our working tree is clean even though we’ve made changes to our remote repository. There is no message to tell us that our local repository is different to our remote repository.
This is because we have not told Git to compare our local repository to our remote repository. This occurred because we did not clone our repository. We initialized a new repository and pulled the contents from an existing repository to our local machine.
We can fix this error by setting an upstream remote branch:
git branch -u origin/master
This tells Git to compare the contents of your current branch to the “master” branch on the “origin” remote. Now, let’s run the git status command again:
On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working tree clean
The Git command line informs us that our local repository contains one more commit than our remote repository. To make this message go away, we must push our changes using the git push command:
git push
Now that we’ve pushed our changes, our local and remote repositories will be the same:
On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean
We’ve fixed the issue!
Conclusion
The Git “nothing to commit, working directory clean” message tells us that we have not made any changes to our repository since the last commit.
If this message appears and the contents of your remote repository are different to your local repository, check to make sure you have correctly set up an upstream branch.
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.