Leem.fin Leem.fin - 2 months ago 10
Git Question

A proper way to ignore my file from version control in my case

My project is already in github. Now, I want to ignore a file which is already version controlled.

What I did was I added that file to

.gitignore
. I understand that for the already tracked file, only add it to
.gitignore
is not enough, so I also did:

git rm my_file


,

My goal is I would like
my_file
being ignored from version control, but still on hard disk so that my project can still run locally. But after I did
git rm my_file
, I am not able to run my project because the
my_file
is missing. I also run command
ls
, and the file is not there.

How can I ignore the
my_file
from version control but still have it in my local disk so that my project can still run locally?

Answer

After listing your file in .gitignore you can just commit and push. this should delete the file on github. Try with:

git add --all
git commit -m "myFile gitignored"
git push

Notice that git add --all will add all your changed to the next commit!

I hope it helps.