Mercurial: Track repo with .hg dir and work-tree in separate directories

Viewed 40

I have often used this approach to dot file management in git, where I create a bare git repo "~/.dotfiles" and us $HOME as a work tree. With the shell alias config I can then add dot files from the home dir quickly (as in config add, config commit

alias config='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'

I wonder if a similar setup is possible in mercurial.

1 Answers

You can use a regular repository for that[^bare] and clone it with the share extension. Creating a new home dir as one-liner:

hg --config extensions.share= share $HOME/.dotfiles $HOME

For more information see hg help share. For information how to ignore changes to untracked files, see hg help hgignore.

[^bare]: If it is important for you to have no files in the .dotfiles, just hg update null in ~/.dotfiles. That’s the root of the repository (before anything got added). Mercurial needs no special bare state.

Related