sandroid.dev
I followed this blog post to add my dotfiles from $HOME to git.
That tutorial creates an alias for a custom git command to use for that directory, called dgit in their case. I found it ever so slighly annoying that I couldn’t just do git status
etc in my $HOME directory, and had to remember another alias for it.
So to fix it, I wrote a wrapper function around the git command to either run the special detached Head command when in $HOME, and regular git anywhere else.
alias dotfiles='git --git-dir ~/repos/dotenv/.git --work-tree=$HOME'
gitOverride() {
# In home directory, call custom detached head git command
if [ $PWD = $HOME ]; then
echo "Running dotfiles git command.."
command git --git-dir ~/repos/dotenv/.git --work-tree=$HOME "$@"
else
echo "running regular git command";
command git "$@"
fi
}
alias git=gitOverride;
And that’s it! Works great, and saves just a little bit of brain space.
Quick paraphrasing of the rest of the process for posterity:
git add -f [filename]