Manage and sync your dotfiles (configuration files) using a Git bare repository. This approach allows easy tracking of dotfiles and seamless application to any new system.
Follow these steps to initialize your dotfiles repository:
- Initialize a Bare Git Repository:
git init --bare $HOME/.cfg
- Create an Alias for Dotfile Management:
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
- Configure Git to Ignore Untracked Files:
config config --local status.showUntrackedFiles no
- Persist the Alias in Your
.bashrc
:
echo "alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'" >> $HOME/.bashrc
- Push Your Changes to a Remote Repository:
git push
Easily apply your dotfiles to a new system with these steps:
- Create the Configuration Alias:
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
- Clone Your Dotfiles Repository:
git clone --bare [email protected]:jpabbuehl/dotfiles.git $HOME/.cfg
- Prevent Git from Tracking Your Home Directory:
echo ".cfg" >> .gitignore
- Backup Existing Dotfiles: To avoid conflicts, backup any existing dotfiles:
mkdir -p .config-backup &&
config checkout 2>&1 | egrep "\s+." | awk {'print $1'} |
xargs -I{} mv {} .config-backup/{}
- Checkout Your Dotfiles:
config checkout
- Update Local Git Configuration:
config config --local status.showUntrackedFiles no
- The
config
command can be used similarly togit
for any dotfiles-related operations. - Customize the
config
alias as per your preference.
Happy dotfile managing! 😄