For years, I've set up my home directory as a git repo:
~ $ ls -a
.git/ .vim/ code/ .bash_history .bashrc .gitconfig .gitignore .vimrc
I'm careful not to commit files that contain sensitive information (e.g. my private ssh key). In fact, I ignore everything except a few files:
~ $ cat .gitignore
# ignore everything
*
# except these
!.bashrc
!.gitignore
!.vimrc
Normally, I have several projects in code/
with their own git repos:
~ $ ls -a code/
ctest/ cpptest/ dwm/
~ $ ls -a code/ctest/
.git/ pointers pointers.c strings strings.c
It never occurred to me that this was strange until a coworker raised concerns about it. Am I somehow abusing git by setting up my home directory this way? Can it lead to problems with programs attempting to use my dot files?
Yes, it is possible to have two git repositories in one directory.
Submodules allow you to keep a Git repository as a subdirectory of another Git repository. This lets you clone another repository into your project and keep your commits separate.
Yes, it is possible. Just do git clone in two different directories with two different repositories.
It's definitely not crazy to put your dotfiles in git. I do it so that I can easily sync my configuration among multiple machines and I'm not alone.
That said, it is poor form to have a git repository in your home directory and then have other repos beneath it.
Some people solve this by checking out their dotfiles repo into a sub directory of $HOME
and then symlinking those files into home. (There are some scripts to help manage this at https://dotfiles.github.io.
Personally, I don't like symlinking and instead create my dotfiles repo in a directory that is not .git
(for example: .dotfiles.git
). You can simply rename the .git
folder to .dotfiles.git
. Then you can:
git checkout --git-dir=.dotfiles.git checkout .profile
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