Troubleshooting misplaced .git directory (nothing to commit) Troubleshooting misplaced .git directory (nothing to commit) git git

Troubleshooting misplaced .git directory (nothing to commit)


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.


This must have happened because by mistake you reinitialized git in the same directory. Delete the .git folder using the following commandGo to repository you want to uploadopen 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 masterAfter that enter the username and password and you are good to go


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.