I store my config files (~/.bashrc
, ~/.emacs
, ~/emacs
, etc.) in git. The way I configured this was simply to add a git repository in the home dir.
I found this approach has some problems:
git gui
takes forever, because it recursively scans the whole home dir.- I sometimes accidentally add files to the config repo that should go to a new repo (I create a new project, say in
~/projects/foo
, forget it doesn't yet have a git repo initialized, and executegit add bar.xyz
in thefoo
directory. This results in a file being added to the config repo).
I'm not sure it is wise to have git repositories nested under a directory that already has a git repository, although I haven't yet encounter any fundamental problems with this.
Is there a better approach, or is this a standard way in which people store local config files in git?
I keep my dotfiles in a Git repository like you do—my home dir is a Git repository.
git gui
: I rarely use it, so I'm not really sure how its performance is impacted by lots of untracked files. However, I do have a~/.gitignore
file that simply contains*
. Perhaps ignoring everything will speed upgit gui
for you.Accidentally adding files: Creating a
~/.gitignore
file that simply contains*
also solves the problem of accidentally adding a file to your dotfiles repository when you forget to initialize a new project repository (it'll tell you to use-f
if you really want to add the file).I've never had a problem with nested repositories.
Some notes:
The main reason why I set my
~/.gitignore
to*
is so thatgit status
doesn't show every file in my home directory. It forces me to usegit add -f
all the time, which is a bit annoying, but not that big of a deal.Get in the habit of using
git clean -dx
instead ofgit clean -dxf
. You'll have to remember to rungit config clean.requireForce false
in new project repositories, but it'll prevent you from accidentally deleting all of your files in your home directory if you're not in the directory you think you're in.Git sometimes decides to reset file permissions. This can be bad if you want to keep sensitive files (
chmod og-rwx
) in your Git repository. I handle this via apost-checkout
hook that fixes permissions of certain files and directories (e.g.,~/.ssh/authorized_keys
).I am using a git repo to manage the dotfiles. It contains:
dotfiles
, which contains the actual dotfiles/dotdirs I want to track.a shell script, to create symbolic link of
dotfiles/.*
in$HOME
, likeThe script is manually runned after I add something new in
dotfiles
(normally by moving a dotfile into repo), or in a new and clean$HOME
.The repo can reside anywhere. I have a clone in
$HOME
on each host I am using.In this way I have a much smaller and non-nested work tree, to track the dotfiles selectively.
p.s. You may want to add entries like
dotfiles/.config/*
to.gitignore
, it contains many files I don't want to track.