I've been getting into game development and I'm trying to tidy up my GitHub repository a bit. I've been uploading media files, and it's blown up the repo size significantly. I want to remove the media directories from GitHub, but I want to keep them on my local machine. I attempted to delete them directly from GitHub, but when I synced with VSCode, it didn't work well for me, leading to the accidental deletion of my local files after a pull. I do have backups of the media files, but I'd prefer not to delete them locally. I've already added the directories to my .gitignore, but I really need help figuring out how to clean up my repository without losing my local files.
4 Answers
If you're not worried about preserving your repo history, the quickest way is to delete the `.git` directory, then run `git init` again and force-push to GitHub. Just make sure to back up your entire project first! Otherwise, your media files will still be part of your git history, which won’t reduce the repo size. If you really want to keep the history and shrink the repo, you’ll need to use `git filter-branch`. That one's a bit tricky, though, so you might want to look up the specific command to remove those large files from your entire history.
Why not just remove the media folders from your local git project directory if you don't want them pushed? Just be aware that the code you're using will need those media files. But yeah, it seems like having thousands of media files on GitHub isn’t the best practice. Maybe consider using another storage option for those?
Deleting files on GitHub itself won't really help you much since GitHub tracks the history of every file. Even if you delete them, they remain in your repository's history, keeping the size high. Starting fresh with a new repository might be the easiest route at this point.
You could try moving your local media files to a different location temporarily. Do a sync of your repository, and once that’s done, move them back into your local folder. With the .gitignore set up correctly, it shouldn't track those files anymore.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String