I have some files that I uploaded in my remote and local Git HEAD, but now I need to delete these files but I need to leave them in my local development environment. These files can not go to the remote because they are private files.
I have some files that I uploaded in my remote and local Git HEAD, but now I need to delete these files but I need to leave them in my local development environment. These files can not go to the remote because they are private files.
Using git rm --cached
As you do not mind the fact that the file continues in previous commits, everything gets easier:
First, include in your .gitignore the name of the files you delete, as indicated by @Bacco in the comments question.
echo file_que_nao_vou_mais_querer > > .gitignore
Now use git rm --cached
to delete the repository file
local, but not from disk:
git rm --cached file_que_no_vou_more_querer
So the file was removed from git but not from the directory itself:
nunks@yokoi:~/test$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: arquivo_que_nao_vou_mais_querer
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: .gitignore