Setting up a bare repository for dotfiles
Initial setup
These first steps are only necessary when setting up a new bare repository for the first time.
# create bare repo
git init --bare $HOME/.dotfiles
cd .dotfiles/
git branch -m main # renamed master to main
# create alias called 'dotfiles' (acts as the 'git')
alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
dotfiles config --local status.showUntrackedFiles no
# add alias to .bashrc (can also be done by hand)
echo "alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'" >> $HOME/.bashrc
# add GitHub repository as remote
dotfiles remote add origin https://github.com/matkv/dotfiles
dotfiles pull origin main
dotfiles push --set-upstream origin main
Setting up the existing repository on a new machine
# make sure the alias is set up in .bashrc
alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
# add the dotfiles repository (that hasn't been cloned yet) to .gitignore in home directory
echo ".dotfiles" >> .gitignore
# clone the actual repository from GitHub
git clone --bare https://github.com/matkv/dotfiles $HOME/.dotfiles
# set up the alias in current shell session (shouldn't be necessary if you added it to .bashrc)
alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
# check out the repository
# this step might fail if some files already exist, these need to be removed or backed up first
dotfiles checkout
# set showUntrackedFiles to no
dotfiles config --local status.showUntrackedFiles no
From this point it should be possible to use the dotfiles
alias to manage dotfiles.
Usage
# example of adding my Visual Studio code config
cd .config/Code/User # settings.json is located here
dotfiles add settings.json
doftiles commit -m 'added VS Code config'
dotfiles push
# viewing all currently tracked files
dotfiles ls-tree --full-tree -r HEAD