Introduction
Using a bare git repo to manage dotfiles is simple (idea from this post, it only requires git
), but now I’ve switch to stow, which in my view, grouping dotfiles together in one folder in easier and cleaner for me to find.
Start
Create the repo
1
| git init --bare $HOME/.dotfiles.git
|
Set git alias for the repo
1
2
| echo "alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles.git/ --work-tree=$HOME'" >> $HOME/.zshrc # or .bashrc
. $HOME/.zshrc
|
Then use this command to not show untracked files on dotfiles status
1
| dotfiles config --local status.showUntrackedFiles no
|
Backup Files
use dotfiles
like your original git
command
1
2
3
4
5
| dotfiles status
dotfiles add .vimrc
dotfiles commit -m "backup .vimrc"
dotfiles remote add origin https://www.github.com/sky-bro/.dotfiles.git
dotfiles push origin master
|
Restore Files
On this computer
1
2
| # rm .vimrc
dotfiles checkout
|
On another computer
1
2
3
4
5
6
| echo 'alias dotfiles="/usr/bin/git --git-dir=$HOME/.dotfiles.git/ --work-tree=$HOME"' >> $HOME/.zshrc
source ~/.zshrc
echo ".dotfiles.git" >> .gitignore # prevent recursion issues
git clone --bare git@github.com:sky-bro/.dotfiles.git $HOME/.dotfiles.git
dotfiles checkout
dotfiles config --local status.showUntrackedFiles no
|