I found an article in Hacker News on how to use git for dot file management. I found that it works well.
git init --bare $HOME/.dot
alias dot='/usr/bin/git --git-dir=$HOME/.dot/ --work-tree=$HOME'
dot config --local status.showUntrackedFiles no
echo "alias config='/usr/bin/git --git-dir=$HOME/.dot/ --work-tree=$HOME'" >> $HOME/.config/zsh/.zshrc
Here is whats going on:
- This first command
git init --bare $HOME/.dot
creates the git repository. In this case a git bare repository. - Line two creates an alias
dot
which is used instead of git, and to save alot of typing. - The third one uses the alias we just created, and sets a flag to the local repository we just created. Then is hides all the files that we don't want to explicitly track.
- Lastly, we are sending that alias we created to the
.zshrc
dot file, again to save alot of typing.
Now all you have to do is add files you want to track. Using the same commands you would with git. Except instead of using the command git
you would replace it with the alias dot
dot status
dot add $HOME/.config/zsh/.zshrc
dot commit -m "Added .zshrc"
dot push origin dotfiles
Make sure you already have your alias configured in zsh (or bash):
alias dot='/usr/bin/git --git-dir=$HOME/.dot/ --work-tree=$HOME'
Now, to ensure the source repository ignores the folder that it will be cloned into.
echo "dot" >> .gitignore
Using git
and not the alias, clone the repository into a bare repositoryin the $HOME
directory.
git clone --bare <git-repo-url> $HOME/.dot
Ensure the current shell you are on has the created alias:
alias dot='/usr/bin/git --git-dir=$HOME/.dot/ --work-tree=$HOME'
If you get an error:
error: The following untracked working tree files would be overwritten by checkout:
.zshrc
.gitignore
Please move or remove them before you can switch branches.
Aborting
This will be because the $HOME folder may have some original files from the old repository still left in it. Either delete them or back them up somewhere and then delete them.
Then re-run checkout
dot checkout
Set the flag to not show untracked files on this local repository.
dot config --local status.showUntrackedFiles no