blog Dotfiles in External Worktree

Original
https://www.atlassian.com/git/tutorials/dotfiles
Tags:
git

As a developer, I tend to keep all kinds of things beyond just code managed with git.

In the past I have used a ~/.dotfiles repo with multiple symlinks, though there are alternate ways to handle it.

Having remembered that bare repositories and alternate work-trees are a thing, I did a short search before finding a tutorial. Initially using their example directly, we arrive at commands that look like this.

git init --bare $HOME/.cfg
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
config config --local status.showUntrackedFiles no
echo "alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'" >> $HOME/.bashrc

This mostly works, but I wanted to test a few more settings.

To use with my git-pending report tool, we need to ensure that git commands work correctly from the git directory itself. To get this to work, I actually changed from using the core.bare setting, to using the core.worktree setting.

config config core.bare false
config config core.worktree ~

core.bare and core.worktree are mutually exclusive, but for our use case, works in the same way.

Now that our worktree setting is configured there, we can simplify our alias some more and still have it work the same way.

alias config='/usr/bin/git --git-dir=$HOME/.cfg/'

I had hoped by fixing core.worktree settings, it would allow other clients like GitUp to also work, but I believe may ignore the status.showUntrackedFiles setting, and ends up crashing (likely from trying to check every file in my home directory). Perhaps this is something I can track down later.