0

I have a some files which I want to remove from git, but I don't want the files to be deleted, either locally or on other developers machines.

(These are files which should never have been in the repo, but I hadn't added them to .gitignore in time.)

Currently, my procedure is:

  1. echo "filename" >> .gitignore
  2. cp filename filename.safe
  3. git rm filename
  4. git commit -a -m"removing filename from repo"
  5. mv filename.safe filename
  6. Ask the other developers to cp filename filename.safe too.
  7. git push origin main
  8. Tell the other developers to git pull; mv filename.safe filename.

This procedure is very fragile, requiring correct timing and good communication.

Is there a safer way to remove a file from a git repo, without it being deleted on my machine or others'?

I have seen: Remove a file from a Git repository without deleting it from the local filesystem but my files are already committed and pushed.

fadedbee
  • 37,386
  • 39
  • 142
  • 236
  • https://stackoverflow.com/search?q=%5Bgit%5D+remove+files+from+repository+don%27t+remove+from+server – phd Nov 25 '20 at 12:39
  • Short answer: No, there is no way. What you do is the only way. – phd Nov 25 '20 at 12:40

0 Answers0