As many people do, I have my dotfiles on GitHub. Having a .git
repository on my home
directory causes me some trouble sometime.
git status
shows me plenty of untracked files. I can partially solve this by writing a .gitignore
that ignore everything that is not a dotfile:
#.gitignore
!.*
.viminfo
.cache
# ...
If I create a new directory mkdir foo && cd foo
and forget to do git init
I will be using my home Git repository instead of the new repository I was supposed to create. So I want to avoid this problem by limiting Git to some folders only.
As I don't usually push
/pull
my dotfiles, I came across this tick in which I simply rename my home Git repository when I don't use it:
alias githide='mv .git .git_hidden'
alias gitshow='mv .git_hidden .git'
Is there a better alternative against these issues?
I use symlinks to those dotfiles and keep them in a separate folder.
$ cd ~
$ ln -s myDotfilesRepo/.gitconfig
If you want to be a bit more advanced you could use GNU Stow to handle dotfiles.
Let's say your dotfiles repo has the following structure:
.
├── git
│ ├── .gitconfig
│ └── .gitignore
Then you could install the whole git package using stow in the following way.
cd ~
git clone git@github.com:user/dotfiles.git
cd dotfiles
stow git
The result is that both files have been symlinked
ls -la ~/.git*
lrwxrwxrwx 1 user user 27 aug. 13 10:17 .gitconfig -> dotfiles/git/.gitconfig
lrwxrwxrwx 1 user user 27 aug. 13 10:17 .gitignore -> dotfiles/git/.gitignore