Hacker News new | ask | show | jobs
by anshargal 1494 days ago
The following .gitignore is my favorite way to commit an (almost) empty folder to git:

  # Ignore everything in this directory 
  *
  # Except this file
  !.gitignore
.gitignore can be present in any directory and there is a way to unignore a wildcard
1 comments

I was looking at someone's dotfiles on Github a while back and they employed this method. Essentially they made their entire home directory a git repo but used gitignore to ignore everything but the dotfiles they wanted to backup. It was a pretty nifty setup
A nifty setup until you run a git command like `git clean -fx` somewhere under your home directory that you think is another git directory but isn't. Happy restore from backups time.
I feel obligated to point out vcsh [1], which is likely already packaged for your operating system.

[1] https://github.com/RichiH/vcsh

The main selling point is that you can set up various git repos for different things. I have one for SSH keys (and no, that does not get pushed anywhere except to my own private server), VIM, neovim, bash, and 'other' (for misc config files like .dir_colors, .gitconfig, etc.).

Another option is to clone the dotfiles repo to your workspace. Then create symbolic links in your home directory. Like:

ln -fs ~/workspace/dotfiles/vimrc ~/.vimrc