We're planting a tree for every job application! Click here to learn more

How-To: portable, maintainable git and shell configs made easy

Ray Smets

22 Jun 2022

2 min read

How-To: portable, maintainable git and shell configs made easy
  • Shell

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 (~/.gitconfig, ~/.zshrc, ~/.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.

Ray

Did you like this article?

Ray Smets

hacker by nature | engineer by trade

See other articles by Ray

Related jobs

Title

The company

title

Remote

Title

The company

title

Remote

Title

The company

title

Remote

Title

The company

title

Remote

Related articles

JavaScript Functional Style Made Simple

JavaScript Functional Style Made Simple

Daniel Boros

12 Sep 2021

JavaScript Functional Style Made Simple

JavaScript Functional Style Made Simple

Daniel Boros

12 Sep 2021

CareersCompaniesSitemapFunctional WorksBlockchain WorksJavaScript WorksAI WorksGolang WorksJava WorksPython WorksRemote Works
email iconhello@works-hub.comUK flag

Ground Floor, Verse Building, 18 Brunswick Place, London, N1 6DZ

US flag

108 E 16th Street, New York, NY 10003

Subscribe to our newsletter

Join over 111,000 others and get access to exclusive content, job opportunities and more!

© 2021 WorksHub

Privacy PolicyDeveloped by WorksHub