Hacker News new | ask | show | jobs
by g0xA52A2A 1258 days ago
I'm a fan of just having my $HOME as a plain git repo with "*" in ~/.gitignore. Having to force add new files is a minor chore but one I'm more than happy to live with.
5 comments

Bare git repos have lots of limitations, namely:

* Maintaining per-machine configurations is a hassle, usually involving a lot of manual branch juggling.

* There's no support for storing secrets in a password manager or in encrypted files.

Read more reasons why dotfile managers are better than bare git repos at https://www.chezmoi.io/why-use-chezmoi/#i-already-have-a-sys...

Been using chezmoi for years and it's great! If you are the person who created this I just want to say thank you! :)
"yadm" effectively does this, just replace "git" with "yadm" and it'll act on your $HOME

Has a couple of other nice things specific to this use case, like letting you have slightly different files based on username or platform.

https://yadm.io/

I started out with yadm but ended up symlinking its .git directory to ~/.git to be able to browse/stage/commit in Fork (https://fork.dev).

To make this manageable, I added this .gitignore:

  \*
  !.\*
  !.hammerspoon/\*/\*
  !.config/\*/\*
  !.ssh/config
  .DS_Store
  .bash_history
  .tig_history
  .lesshst
  .python_history
  .wget-hsts
  .zsh_history
  .CFUserTextEncoding
  .Xauthority
  /.config/mcd/.cache/
  /.config/mcd/.local/
  /.config/legendary/
This makes use of the fact that .gitignore patterns are evaluated in order. It basically makes git only care about dotfiles in the home directory, files under .config, .ssh and .hammerspoon. Specific files/dirs that match that filter can still be ignored (e.g. .bash_history).

This is very straightforward and works quite well, so I don't see the need for yadm anymore. The one issue I have with it, is that in the terminal I'm always in a git context (shown in the shell prompt) in any directory under $HOME.

That's clever, but it also seems like a bit of a hassle. It also seems incredibly non-hermetic and prone to accidental pollution.

What about putting all configs into a single git managed directory and using tooling to install the appropriate symlinks?

  # Save the repo to `~/.dotfiles`; the `--bare` option prevents Git from making
  # a mess of your home directory.
  git clone --bare ... ~/.dotfiles

  # Set up an alias for this shell session (it's also in ~/.config/aliasrc).
  alias dots='git --git-dir=$HOME/.dotfiles --work-tree=$HOME'

  # Make sure we don't show untracked files in `git status` output.
  dots config --local status.showUntrackedFiles no

  # Checkout all local files.
  # NOTE: This might overwrite existing files, or you might need to stash files
  # before proceeding. Look before you leap. If you have an existing setup,
  # consider checking out individual files as needed and testing the
  # configuration piecemeal, instead of doing a complete checkout.
  dots checkout

  # Make sure we can access remotes properly. The `--bare` option requires us to
  # do this manually.
  dots config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"

  # Make sure we are set up to track the remote `master` branch. Again, this is a
  # consequence of cloning with `--bare`.
  dots branch --set-upstream-to=origin/master master
  dots switch master

  # Fetch to make sure everything is configured correctly.
  dots fetch origin
The git ignore file set up prevents accidental pollution.

A script and/or symlinks is overhead.

This is what I do also.