Lately I have been through a computer mayhem: my honorable Macbook Pro left me (may he find peace in the afterlife) and at work I’ve been changing machines like clothes for at least a month. As a developer, you know that nowadays you basically don’t lose many things in that kind of situation, at least application wise (the beauty of the cloud, they say). And all around, if you were using the lost/dead/burnt (what are you doing to those poor machines??) computer mostly for developing stuff, cloud or not, there are good chances you got all of your projects store in repositories hosted on GitHub, Bitbucket or wherever it pleases you. If you aren’t using any form of versioning control in your project you should really stop reading this and start questioning the meaning of life. No, seriously, go check out Git and enjoy developing once again.
Anyway, what should frighten you in case your machine was lost, is the most delicate stuff you developed during all of your hard work: your dotfiles. I’m speaking of those tiny little files that tell Git who you are, define that precious alias linked to the most complex command you now don’t even remember and hold all of your configurations. Not to mention that if you are a Vim user losing your
.vimrc may drive you crazy, depending on how much time you invested in it. (Nah, it will just drive you crazy.)
tl;dr You don’t want to lose your dotfiles.
Needless to say, there is a very simple solution that can prevent you from going through this painful experience. Storing your dotfiles in Git repository.
If you’re already on board with this you may ask “Who wouldn’t do that?”, and you’d surprised from the answer. I personally started taking care of this a couple years ago, and can’t think of how it was before. Not to mention that if you store those files in a repo it becomes super easy to port them to different environments, whether it’s a server you manage or a colleague with whom you want to share some or all of your configuration. They can fork your repo and add their personal flavour, just as with any other project under version control.
Let me show you how I achieved this, though I’m sure there are many other ways.
Start by creating a folder named
dotfiles in your home (
~/), then start moving all the files you want to include in the repository, removing the
. from their names. Do keep in mind that if you want to make this repo public you should avoid including files that hold personal or business sensitive informations.
Really, be extra careful about what you include in your repository if your plans are to make it public!
To turn this folder in a repo, in case you’re not aware, run
$ git init $ git add --all $ git commit -m "First commit"
Now you may argue that there are no more usable dotfiles in your root, and you’d be right! The next involves a tool called RCM, made by thoughtbot, and happens to be a management suite for dotfiles. To install it on macOS run
$ brew tap thoughtbot/formulae $ brew install rcm
If you’re on a Debian-based system run
$ wget -qO - https://apt.thoughtbot.com/thoughtbot.gpg.key | sudo apt-key add - $ echo "deb http://apt.thoughtbot.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/thoughtbot.list $ sudo apt-get update $ sudo apt-get install rcm
We’re about to use RCM to create dotfiles symlinks from your home directory to your
/dotfiles/ directory. Before doing this, add a file called
rcrc to your
~/dotfiles directory. The content of
rcrc should be as follow:
EXCLUDES="README.md LICENSE" DOTFILES_DIRS="$HOME/dotfiles"
This will tell RCM what files NOT to symlink and where your dotfiles are now stored. Once that’s done you can run:
$ env RCRC=$HOME/dotfiles/rcrc rcup
After this you should be back to having all of your dotfiles in your home directory, but those are just symlinks to files that are now stored in a Git repository. To have it backed up remotely, if you’re not familiar with Git, you can create a free public repo on GitHub.
After that’s done, your loyal dotfiles will be able to follow you wherever you go, and if you keep your repo public you may even inspire others! (How do you think I came up with this idea a couple years ago? 🍻)
Whenever you edit your dotfiles, remember to track those changes in the repo
$ git add --all $ git commit -m "Add super useful alias" $ git push
And that’s it, if you want to take a look at a final result you can check out my repository. Don’t judge me too hard, there’s even an alias that starts an audio clip about a famous wrestler… See if you can find it! 😎 (we just find it fun in the office from time to time).
Hope you enjoyed this, it’s incredible in how many simple ways a repo can save your life!