Easily track and synchronize your machine’s config files (dotfiles) using Git
Step 1: Initialize a new Git repository
-
Initialize a bare Git repository in your home directory
cd git init --bare $HOME/.dotfiles
-
Create an
config
alias instead ofgit
to work specifically with dotfilesalias config='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
-
Hides untracked files to keep your
config status
output clean.config config --local status.showUntrackedFiles no
-
Add the alias to your shell config file
echo "alias config='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'" >> $HOME/.zshrc
-
Reload your shell
source $HOME/.zshrc
Step 2: Connect to a remote repository
-
Create a new repository on GitHub
-
Link the local repository to the remote
config remote add origin YOUR_REPO_URL
-
Push the repository to GitHub and set the default branch
config push -u origin main
Step 3: Manage dotfiles
With the setup complete, you can now use the config
alias to track files in your $HOME
directory
-
Check the repository’s status
config status
-
Add and commit a file:
config add .zshrc config commit -m "feat: add new alias"
-
Push changes to the remote repository:
config push
Repeat these steps for any additional files you want to track