Remove file from the repository but keep it locally
I have a folder which I’d like to remove in my remote repository. I’d like to delete it, but keep the folder in my computer
- How can I git pull ignored files?
- gitignore: Ignoring a folder (anywhere) except for a subfolder (anywhere)
- Git pass gitignore file as command line argument
- What is the exact impact of following content of `.gitignore` file in one of subdirectories?
- git add only modified changes and ignore untracked files
- what will happen if I add a file to my git repo and later add a pattern in gitignore that suggests that file is to be ignored
2 Solutions collect form web for “Remove file from the repository but keep it locally”
git rm --cached -r somedir
Will stage the deletion of the directory, but doesn’t touch anything on disk. This works also for a file, like:
git rm --cached -r somefile.ext
Afterwards you may want to add
somefile.ext to your
.gitignore file so that git doesn’t try to add it back.
I would just:
- Move the folder out of your working tree
git rmthe folder, commit the change
- Add to
.git/info/excludes), commit the change
- Move the folder back