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
-
4possible duplicate of Git: Remove a file from the repository without deleting it from the local filesystem – Cascabel Aug 12 '10 at 16:36
-
Please look at the suggested related questions as you're writing yours - the duplicate was probably one of the first two. – Cascabel Aug 12 '10 at 16:36
-
Another duplicate: stackoverflow.com/questions/1273108/… – Cascabel Aug 12 '10 at 16:39
-
4Possible duplicate of Remove a file from a Git repository without deleting it from the local filesystem – Michael Freidgeim Mar 1 '17 at 0:54
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 somefile.ext
Afterwards you may want to add somedir/
or somefile.ext
to your .gitignore
file so that git doesn't try to add it back.
-
27And then add the path to .gitignore so git doesn't try to make you add it later. – grossvogel Aug 12 '10 at 16:24
-
3Will this result in (files in) the directory being removed when he pulls from the remote? – bstpierre Aug 12 '10 at 16:24
-
Not when he pulls; the files will stay removed locally during the pull's automatic merge process. After that, a push will cause the files to be removed server-side. – Walter Mundt Aug 12 '10 at 16:38
-
7What happens if I have a third remote? Will the corresponding files get removed in a future pull? I ask because I feel this is quite a common use case, i.e. check some files into the repo, realise at a later date that they diverge between remotes, for good reason, and should never have been in the repo in the first place, want to resolve that by keeping all local checkouts exactly as they are, but removing the files from the repo. – Bobby Jack Jan 22 '15 at 18:33
-
7
I would just:
- Move the folder out of your working tree
git rm
the folder, commit the change- Add to
.gitignore
(or.git/info/excludes
), commit the change - Move the folder back
-
10
-
-
1@loostro just don't move it to another block device. The most file systems will just update the file's inode, and not literally move the entire directory – 648trindade Mar 28 '18 at 4:11