DEV Community

Joshua Ferguson
Joshua Ferguson

Posted on

I'm trying to figure out a way to use git to ignore local deletions

I recently had the idea to try and create a modular dotfile setup by using
git update-index --skip-worktree "$file_or_dir_in_question". the goal was to be able to keep all my dotfiles in a centralized repository, then pull them and delete the ones unnecessary for that system, be that because the required package isn't installed or it was something specific to another distro. Here's a script I wrote to do this automatically. I also did the same for a repository I use to keep track of all my work for my classes over the last two semesters.

So I accidentally deleted a lot of my old dotfiles (thankfully most weren't necessary) last night. I figured it was a bug in the script(ie the local worktrees weren't being ignored, but after using this same technique for my classes, verifying they were being ignored, and seeing that the files were still being listed as deleted via the commit messages, I realized that the script was working properly, but either git or skip-worktree was the wrong tool for the job.

What could I do with git, or another version control tool in order to get the result I want, i.e. keep the files/directories in remote but delete the local copies without pushing those deletions when I need to update the remote repository?

Top comments (0)