Remove Files From Git Repo as in Gitignore
After you committed/pushed files to GIT repository, if you decide to ignore some files/directories using
.gitignore then they won’t be automatically removed from git repository. Following command can be used for removing those ignored files from repo.
git rm -r --cached . git add . git commit -m ".gitignore fix" git push
To remove the the ignored files/dirs from repo, use GIT remove command as follows.
git rm -r --cached .
|git rm||Remove command|
|-cached||Your file system is uneffected but it removes the files only in you
|.||Include all files. if you want to remove a specific file then use
Now add the all files except those mentioned in .gitignore by using this command
git add .
Commit your changes
git commit -m ".gitignore fix"
Now check your server repository, it shouldn’t have the files mentioned in
- You can execute the above mentioned remove command with
--dry-runoption to see what will happen. i.e. Adding this flag will not make any change but it will tell you what it is going to do.