[Solved] git status (nothing to commit, working directory clean), however with changes commited

I found many questions with similar subject, but I didn’t found any practical guidance about this issue: why git status informs me nothing to commit, working directory clean, even tough I have made a modification at my local branch?

Here are the steps which I followed:

  • git init [On branch master – Initial commit, nothing to commit (create/copy files and use “git add” to track)]
  • git remote add https://github.com/username/project.git
  • git pull origin master
  • touch test
  • git add test
  • git commit -m "Adding file for test purposes only."
  • git status [On branch master – nothing to commit, working directory clean]

If I do a git push, the modification is committed to the remote branch. I just want to perform “git status” after my modifications, and receive the information that I have changes on my local branch that must be pushed to the remote branch of the project.

Can someone tell me what’s going? Straight to the point, please.

Thanks in advance SO community!

Solution #1:

Your local branch doesn’t know about the remote branch. If you don’t tell git that your local branch (master) is supposed to compare itself to the remote counterpart (origin/master in this case); then git status won’t tell you the difference between your branch and the remote one. So you should use:

git branch --set-upstream-to origin/master

or with the short option:

git branch -u origin/master

This options –set-upstream-to (or -u in short) was introduced in git 1.8.0.

Once you have set this option; git status will show you something like:

# Your branch is ahead of 'origin/master' by 1 commit.
Respondent: ivanleoncz

Solution #2:

git status output tells you three things by default:

  1. which branch you are on
  2. What is the status of your local branch in relation to the remote branch
  3. If you have any uncommitted files

When you did git commit , it committed to your local repository, thus #3 shows nothing to commit, however, #2 should show that you need to push or pull if you have setup the tracking branch.

If you find the output of git status verbose and difficult to comprehend, try using git status -sb this is less verbose and will show you clearly if you need to push or pull. In your case, the output would be something like:

master…origin/master [ahead 1]

git status is pretty useful, in the workflow you described do a git status -sb: after touching the file, after adding the file and after committing the file, see the difference in the output, it will give you more clarity on untracked, tracked and committed files.

Update #1
This answer is applicable if there was a misunderstanding in reading the git status output. However, as it was pointed out, in the OPs case, the upstream was not set correctly. For that, Chris Mae’s answer is correct.

Respondent: Chris Maes

Solution #3:

The problem is that you are not specifying the name of the remote:
Instead of

git remote add https://github.com/username/project.git

you should use:

git remote add origin https://github.com/username/project.git
Respondent: dubes

Solution #4:

I had the same issue because I had 2 .git folders in the working directory.

Your problem may be caused by the same thing, so I recommend checking to see if you have multiple .git folders, and, if so, deleting one of them.

That allowed me to upload the project successfully.

Respondent: Jonathan

Solution #5:

Small hint which other people didn’t talk about: git doesn’t record changes if you add empty folders in your project folder. That’s it, I was adding empty folders with random names to check wether it was recording changes, it wasn’t.
But it started to do it as soon as I began adding files in them.
Cheers.

Solution #6:

just do the following steps

  1. remove .git folder

  2. add the git repo

    $ git init

    $ git add origin master repo.git

  3. then pull or push the files

Done!!!

Respondent: ReptiIe

Solution #7:

This solution might not be suitable for most situations but it is a lifesaver in a situation where; you are making major changes then the git commit is working but when you make a slight change in one file (let’s say in CSS file) then the git commit won’t work.

I faced this issue and I tackled this situation by making changes on GitHub and committing there then running git pull on my local repository.

Solution #8:

Follow these steps for commits

1.making new branch for protect your files

git checkout --orphan latest_branch

2.add it into new branch

git add -A

3.commit

git commit -am "commit message"

4.check git status

git status

5.files or correct try to push in this step

git push -f origin main

Now your files are safe

Clear your branches if you don’t want specific and create it what branch your want

eg:master or main

6.Delete the branch

git branch -D main

7.Rename the current branch to main

git branch -m main

8.Finally, force update your repository

git push -f origin main
Respondent: Ali Hassan

Solution #9:

Delete your .git folder, and reinitialize the git with git init, in my case that’s work , because git add command staging the folder and the files in .git folder, if you close CLI after the commit , there will be double folder in staging area that make git system throw this issue.

Respondent: ßãlãjî

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.