51

I started getting this message. No matter what I edit and try to commit, it says there is nothing to commit. Looks like git does not see my working directory and looking somewhere else.

If I run git status it outputs the same:

nothing to commit (working directory clean)

If I create new branch and edit something, then same thing happens. This started happening when I needed to fix merge clashes. When I wanted to merge my one branch with master branch, I had to manually fix it and I needed my files to look exactly as in that branch overwriting master branch those same files. So I added those files and it let me merge it. But then no matter what I change it shows as there is nothing to commit.

What could be done here?

dreftymac
  • 31,404
  • 26
  • 119
  • 182
Andrius
  • 19,658
  • 37
  • 143
  • 243

16 Answers16

22

Found what was wrong. I don't understand how, but .git directory path somehow was changed to other path than I was working in. So then anything I changed was not checked, because git was checking in other place. I noticed it, when I reinitialized it and it showed that it reinitialized entirely different directory. When I cd .. from my current directory and cd to it back again and then reinitialized yet again, then it switched back to correct .git directory and started seeing my changes.

Andrius
  • 19,658
  • 37
  • 143
  • 243
  • Thaks @Andrius for the answer! – Gediminas Šukys Jun 13 '14 at 06:25
  • 7
    I don't exactly follow. How exactly did you know `git` was looking in the wrong place? And how did you fix this?? I tried `git init` but this didn't change anything... – MichaelChirico Jun 04 '15 at 19:04
  • Well it was my mistake. I was on different directory than I thought I was. And every time I tried to commit changes, it didn't registered, because i was looking in wrong directory. – Andrius Jun 05 '15 at 06:15
14

This must have happened because by mistake you reinitialized git in the same directory. Delete the .git folder using the following command Go to repository you want to upload open the terminal and then use the following commands

  1. remove the .git repository sudo rm -r .git
  2. Now again repeat from initializing git repo using git init
  3. then git commit -m "first commit"
  4. git remote add origin https://github.com/user_name/repo
  5. git push -u origin master After that enter the username and password and you are good to go
Lukas Würzburger
  • 6,543
  • 7
  • 41
  • 75
Mahi
  • 1,164
  • 17
  • 24
7

For people working in public open source projects, if you face this behaviour, it is most likely that the file you are editing is excluded from the git repository using .gitignore. I faced the same behaviour, and after hours I found that the file I was making the change is excluded in .gitignore because it is a settings file, and every one will have their own local version.

palerdot
  • 7,416
  • 5
  • 41
  • 47
3

Check the location whether it's the right location of the git project.

Gank
  • 4,507
  • 4
  • 49
  • 45
3

On branch master Problem it is committed already nothing to commit (working directory clean) if faced this problem then just only use the following command

git push -u origin master

or

git reset
git add .
git commit -m "your commit message"
git push -u origin master
gofr1
  • 15,741
  • 11
  • 42
  • 52
Anuj
  • 31
  • 2
2

For anyone seeing this problem, the simplest solution I found was to just "git clone" your repo and delete the old directory. This should set up your pathing correctly by default.

kaid
  • 1,249
  • 2
  • 16
  • 32
2

I had the same issue. The branch I was working on wasn't being tracked. The fix was:

git push orgin

This fixed it temporarily. To make the changes pertinently I:

git config push.default tracking
Jon Kennedy
  • 472
  • 2
  • 6
  • 21
2

In my case I had previously initialized a git directory where I was trying to create a new one. I just deleted all the old files and started from scratch.

Leviathan
  • 43
  • 6
1

Here is another twist on it. My .gitignore file seemed to have been modified / corrupted so that a file I was ignoring

e.g.

/Project/Folder/StyleCop.cache

got changed to this (Note now 2 separate lines)

/Project/Folder
StyleCop.cache

so git was ignoring any files I added to the project and below.

Very weird, no idea how the .gitignore file was changed, but took me a while to spot. Once fixed, the hundreds of css and js files I added went in.

richardb
  • 943
  • 1
  • 10
  • 27
1

Encountered this while using SourceTree, fixed it by

  1. First stash your current uncommitted changes.
  2. Apply / Unstash the same changes using Sourcetree.

Worked like a charm.

rustylepord
  • 5,681
  • 6
  • 36
  • 49
0

I just had this problem myself because I was in the wrong folder. I was nested 1 level in, so there were no git files to be found.

When I execute cd .. to the correct directory, I was able to commit, as expected.

R3tep
  • 12,512
  • 10
  • 48
  • 75
0

try removing the origin first before adding it again

git remote rm origin
git remote add origin https://github.com/abc/xyz.git
khalidh
  • 875
  • 2
  • 12
  • 34
0

Don't try commiting / adding files. Just run the following 2 commands (:

    git remote add origin http://xyzremotedir/xyzgitproject.git
    git push origin master
Walk
  • 1,531
  • 17
  • 21
0

Go to your workspace folder

  1. find .git folder
  2. delete the folder and its contents
  3. use git init command to initialize.

Now it will show what all the files can be committed.

slfan
  • 8,950
  • 115
  • 65
  • 78
0

I have faced the same issue with git while working with angular CLI 6.1.2. Angular CLI 6.1.2 automatically initializes .git folder when you create a new angular project using Angular CLI. So when I tried git status - it was not detecting the whole working directory.

I have just deleted the hidden .git folder from my angular working directory and then initialized git repository again with git init. And now, I can see all my files with git status.

alps_ren
  • 11
  • 2
-2

if .git is already there in your dir, then follow:

  1. rm -rf .git/
  2. git init
  3. git remote add origin http://xyzremotedir/xyzgitproject.git
  4. git commit -m "do commit"
  5. git push origin master
bfontaine
  • 18,169
  • 13
  • 73
  • 107
  • 1
    That won't work, as the push will fail and more importantly you loose the entire history of the repository. And: this does not answer the question. – jhoepken Sep 15 '17 at 11:33
  • Please never encourage confused users to `rm -rf .git/`, as that's the one operation `git` can't recover from. – Adam Bliss Jul 15 '19 at 19:05