Backup config files with git
Evolution Note: This tutorial was written in January 2019 and reviewed in October 2026. Managing dotfiles with lightweight version control remains a dependable habit when configuring remote servers and local workstations. For current technical publications, visit the homepage.
The home directory on any Linux workstation accumulates a variety of configuration files over time. Storing these files in Git allows you to restore familiar editor setups and shell aliases whenever you spin up a new virtual private server.
Because multiple tools place files directly into $HOME, turning the entire user directory into a single Git repository is impractical. A clean alternative is maintaining separate, isolated Git directories for distinct tool configurations like Emacs and Bash.
Initializing Isolated Git Directories
Instead of keeping a standard .git folder in your home root, you can initialize separate metadata directories for each configuration cluster:
cd ~
git init
cp -rf .git .git-emacs-config
rm -rf .git
Follow the same pattern for shell configurations:
git init
cp -rf .git .git-bash-config
rm -rf .git
Filtering Tracked Files with Info Exclude
Because other repositories might live inside your home directory, placing a global .gitignore in $HOME can interfere with subprojects. Using each repositoryβs private exclude file (info/exclude) solves this neatly.
For the Emacs configuration, append the following patterns to .git-emacs-config/info/exclude:
*~
.*
*
!.emacs.d
!.emacs.d/*
!.emacs
For the shell configuration, configure .git-bash-config/info/exclude:
.*
*
!.bash_history
!.bash_logout
!.bash_profile
!.bashrc
!.zlogin
!.zshrc
Creating Shell Aliases for Ergonomic Workflow
Running Git commands with the explicit --git-dir flag directs Git to track the home directory without creating collisions:
git --git-dir=$HOME/.git-emacs-config --work-tree=$HOME add .
git --git-dir=$HOME/.git-emacs-config --work-tree=$HOME commit -m "Update emacs configuration"
git --git-dir=$HOME/.git-emacs-config --work-tree=$HOME push origin main
To simplify daily use, define convenience aliases in your .bashrc or .zshrc:
alias config-emacs='git --git-dir=$HOME/.git-emacs-config/ --work-tree=$HOME'
alias config-bash='git --git-dir=$HOME/.git-bash-config/ --work-tree=$HOME'
With these aliases in place, switching branches or syncing updates across machines requires just a single command.
Unlike symlink managers like GNU Stow or dedicated dotfile utilities that introduce extra package dependencies on minimal server images, this approach relies entirely on standard Git plumbing available on virtually any Unix distribution. You can branch your configurations for different working environments, such as development laptops versus headless cloud servers, without needing to create separate user accounts.
Working on complex AI or automation pipelines?
Let's discuss system architecture, deterministic state boundaries, or workflow design.
Grab a Coffee