How to manage local files in a shared git repository
Problem description
When working on a shared git repository, I found I often need to keep some files locally that I don’t want to push to the remote repository. These files are useful for my personal development setup but are not relevant to the rest of the team.
In my case, I use mise to manage my local dev tools, so I have a mise.local.toml file that contains configurations for tools I use. This file is not meant to be shared with the team, and I don’t want it to be tracked by git.
I also often run git clean -fxd to create a pristine working directory to test a clean build, but I don’t want this command to delete my local mise.local.toml file. However, since it’s untracked and not ignored, git clean -fxd will remove it.
Solution
- Add the file to
~/.config/git/ignoreto prevent it from being tracked by git. This way, it won’t show up ingit statusor be included in commits. 1 - Add
-e "*.local.*"to thegit cleancommand to exclude files matching this pattern from being deleted. This allows you to keep your local configuration files intact while still usinggit clean -fxdto remove other untracked files. 2