Tuesday, 17 August 2021

GIT for .gitignore to work for files ignored but already in remote repo

https://stackoverflow.com/questions/25436312/gitignore-not-working

https://stackoverflow.com/questions/25436312/gitignore-not-working

NOTE: this process for adding an existing remote repo file to git ignore is not ideal for multiple people using the repository, as the remote repo file will be removed after step2), and when other people pull from remote the local file will be gone as well. They have to manually add that local file back

step1)

add file u want to start to ignore but already in remote repo to .gitignore (

git add .

git commit -m ""

git push

After this step, file added to .gitignore will not be ignored as file is previously in remote, and git is still tracking



step2)

git rm -rf --cached .

git add .

***** To rever local changes, can always use git reset --hard

git commit -m ""

git push


This removes all files from the repository and adds them back (this time respecting the rules in your .gitignore).

No comments:

Post a Comment