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.~/projects/foo
, forget it doesn't yet have a git repo initialized, and execute git add bar.xyz
in the foo
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?
The short answer to your question is Yes. I wouldn't hesitate to recommend Git (or any other version control software) to keep track of configuration files.
Create and Manage a Git RepositoryClick on the Settings page for your account, then on the SSH and GPG Keys section. On that page, click the “New SSH key” button. After you have clicked on the New SSH key button a panel will appear in which you should then input a Title for the key and the private key itself.
Using submodules One way out of the problem of large files is to use submodules, which enable you to manage one Git repository within another. You can create a submodule, which contains all your binary files, keeping the rest of the code separately in the parent repository, and update the submodule only when necessary.
As the git repository is contained inside your work directory, just place the work directories wherever is most convenient.
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
, like
for dotfile in dotfiles/.* ; do
case $(basename $dotfile) in
.)
;;
..)
;;
*)
ln -sv $(realpath dotfile) $HOME/$(basename $dotfile)
;;
esac
done
The 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.
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 up git 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 that git status
doesn't show every file in my home directory. It forces me to use git 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 of git clean -dxf
. You'll have to remember to run git 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 a post-checkout
hook that fixes permissions of certain files and directories (e.g., ~/.ssh/authorized_keys
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With