Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 427
Rodrigo Souza Avatar asked Aug 12 '10 16:08

Rodrigo Souza


People also ask

How do I remove a file from a git repository?

The easiest way to delete a file in your Git repository is to execute the “git rm” command and to specify the file to be deleted. Note that by using the “git rm” command, the file will also be deleted from the filesystem.

Does git rm remove local file?

git rm will not remove a file from just your working directory. (There is no option to remove a file only from the working tree and yet keep it in the index; use /bin/rm if you want to do that.)

What steps can a user take to remove a personal file from the repository while keeping a local copy that won't be tracked by git?

"git rm --cached <file>" would remove <file> from version control, while keeping it in the working repository.


2 Answers

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.

like image 156
jamessan Avatar answered Oct 14 '22 18:10

jamessan


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
like image 35
Jeff Avatar answered Oct 14 '22 16:10

Jeff