Accidentally committed .idea directory files into git
if you haven't push to git
git rm .idea/ -r --cached
git add -u .idea/
git commit -m "Removed the .idea folder"
if "git rm .idea/ -r --cached" throw an error "fatal: pathspec '.idea' did not match any files" and already push to git with .idea on it.
git push origin --delete remoteBranchName
git add . //Everything is up to date
git commit -m "Removed the .idea folder" //Nothing to commit
git push origin remoteBranchName
Add .idea directory to the list of ignored files
First, add it to .gitignore
, so it is not accidentally committed by you (or someone else) again:
.idea
Remove it from repository
Second, remove the directory only from the repository, but do not delete it locally. To achieve that, do what is listed here:
Remove a file from a Git repository without deleting it from the local filesystem
Send the change to others
Third, commit the .gitignore
file and the removal of .idea
from the repository. After that push it to the remote(s).
Summary
The full process would look like this:
$ echo '.idea' >> .gitignore
$ git rm -r --cached .idea
$ git add .gitignore
$ git commit -m '(some message stating you added .idea to ignored entries)'
$ git push
(optionally you can replace last line with git push some_remote
, where some_remote
is the name of the remote you want to push to)
Its better to perform this over Master branch
Edit .gitignore file. Add the below line in it.
.idea
Remove .idea folder from remote repo. using below command.
git rm -r --cached .idea
For more info. reference: Removing Files from a Git Repository Without Actually Deleting Them
Stage .gitignore file. Using below command
git add .gitignore
Commit
git commit -m 'Removed .idea folder'
Push to remote
git push origin master
You can remove it from the repo and commit the change.
git rm .idea/ -r --cached
git add -u .idea/
git commit -m "Removed the .idea folder"
After that, you can push it to the remote and every checkout/clone after that will be ok.