Sunday, November 27, 2022

Delete files from Git repo and history


Follow these steps to delete single or multiple files from your Git repository and prune it from history. You should also add the file(s) to .gitignore (Step 5) to avoid committing the same files to your repo again in the future.
  1. git clone <repo-path>
  2. git rm file1 file2
  3. git filter-repo --force --invert-paths --path file1
  4. git filter-repo --force --invert-paths --path file2
  5. nano .gitignore 
  6. git add .
  7. git commit -m "deleted file1 file2"
  8. git remote add origin <repo-path>
  9. git remote -v
  10. git push origin --force --all
  11. git push origin --force --tags

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.