Managing Dotfiles with Git and Github
Looking for the perfect solution to managing your dotfiles without having to use symlinks? This configuration will allow you to easily migrate your dotfiles to every unix machine you touch while maintaining version control.
Never leave home without your dotfiles again!
Full credit for this solution goes to StreakyCobra, seliopou, and telotortium on the Y Combinator forums. Thank you, guys!
Warning! If caution isn't taken with the instructions below, you may accidently delete your dotfiles. I highly recommend backing up your dotfiles just in case.
Setting up your dotfiles
- Create an empty github repo for your dotfiles.
    
https://github.com/YOURUSERNAME/dotfiles - Clone the repo into a temporary directory.
    
git clone --separate-git-dit=$HOME/.dotfiles https://github.com/YOURUSERNAME/dotfiles $HOME/dotfiles-tmp - Copy the contents of that directory into your home folder.
    
cp ~/dotfiles-tmp/. ~ -r - Remove the ~/.git file
    
rm ~/.gitWarning! If you get warnings about a directory not being a git repo, or if your shell becomes very slow / zgen starts throwing errors, you probably forgot to delete this.
 - Delete the temporary directory.
    
rm ~/dotfiles-tmp -r - The first time you setup these dotfiles, add the following 
dotfilesalias to your shell dotfile (.bashrc, .zshrc, etc), or wherever you put your aliases.alias dotfiles='`which git` --git-dir=$HOME/.dotfiles --work-tree=$HOME' - Source your shell dotfile (.bashrc, .zshrc, etc) to make sure the 
dotfilesalias is now available to you.source ~/.zshrc - To prevent 
$ dotfiles statusfrom displaying every file in your home directory as being untracked, run:dotfiles config status.showUntrackedFiles no 
Adding dotfiles to the git repo
- Use 
dotfilescommand the same way you would use thegitcommand.dotfiles add ~/.zshrc ~/.tmux.conf dotfiles commit -m "Added .zshrc and .tmux.conf" dotfiles push 
Pulling dotfiles to new machines
- Simply do steps 2, 3, 4, and 5 from the initial setup instructions.
 - Or… you could make a script on another gitrepo or on your github pages that runs those steps for you.
    
#!/bin/sh git clone "--separate-git-dir=$HOME/.dotfiles" https://github.com/$1/dotfiles $HOME/dotfiles-tmp cp ~/dotfiles-tmp/. ~ -r rm ~/.git rm ~/dotfiles-tmp -rTo use my script:
curl -lO https://techknowfile.dev/scripts/dotfiles.sh sudo chmod +x ./dotfiles.sh ./dotfiles.sh YOURGITHUBUSERNAME