22 Jun 2022
2 min read
In case you have ever had to deal with getting your shell and git config dialed in on a new unix machine, this how-to is for you. It also for those of who you want to keep configs in sync across multiple machines.
I recently had to setup a brand new computer without being able to restore from backup and this little solution not only made the setup very simple and quick but also maintainable. It will be useful moving forward to keep a single source of config truth that is easily obtainable between machines.
In order to streamline a repeatable setup exactly as desired the (not so) secret is leveraging git and (fairly secret) symlinks.
Git clearly is great for the version control properties of the relevant config files (
~/.oh-my-zsh/custom, etc). Definitely keep these files (sans sensitive information) in version control.
However, how to manage config files that span multiple directories? The files listed above all live in the home directory, but what if a config file you want to track was in
~/dev/configs/myawesomeconfg? This where one of the advantages of symlinks come into play.
By creating a symlink from your config-repo directory to a config's regular path all disparate configs can be managed in one git directory. Furthermore by using symlinks, instead of hardlinks, one can then pull updates from the repo (say from another machine you work on) and the files that are symlinked in their default locations are also updated.
For example, I create a symlink for my
.gitconfig from my config-repo,
~/dev/config-repo/.gitconfig, to its default location, the home directory. This is done by:
cd ~ ln -s ~/dev/config/.gitconfig .
Now if that git managed
.gitconfig file is ever updated and I pull the changes in config-repo locally the git config, in its "normal" place in the home directory is also updated. And visa versa if I update
~/.gitconfig the changes are reflected in git-repo change log. I use this same setup for a .zshrc config file.
This setup also works for my
~/.oh-my-zsh/custom directory. I allow each machine's oh-my-zsh installation to manage it's own installation, but I symlink the custom directory so I get all my shell aliases and functions.
cd ~/.oh-my-zsh rm -rf custom ln -s ~/dev/config/oh-my-zsh/custom .
In conclusion, this solution enables tracking essential configurations in version control for maintainability and enables interoperability between machines. This can of course be extended to any type of config files / directories. I hope this how-to was informative and helpful.
hacker by nature | engineer by trade
See other articles by Ray
Ground Floor, Verse Building, 18 Brunswick Place, London, N1 6DZ
108 E 16th Street, New York, NY 10003
Join over 111,000 others and get access to exclusive content, job opportunities and more!