One of my employers presented me with two development machines on my first day (a desktop and a laptop machine). As I started configuring my development environment I realized I wanted the configuration to be synchronized across both machines. I wanted my bash profile, aliases, vimrc, gitconfig and all those types of files to be the same on both machines.
Storing my dotfiles using Git
I created a new directory ~/dotfiles
and initialized it as a git repository. I added all the desired configuration files to this directory:
~/dotfiles $ ll drwxr-xr-x 12 riley.macdonald wheel 408 Nov 30 09:06 . drwxr-xr-x 29 riley.macdonald wheel 986 Nov 30 15:31 .. -rw-r--r-- 1 riley.macdonald wheel 844 Nov 30 09:06 .bash_aliases -rw-r--r-- 1 riley.macdonald wheel 274 Nov 22 10:19 .bash_exports -rw-r--r-- 1 riley.macdonald wheel 106 Nov 15 16:37 .bashrc drwxr-xr-x 15 riley.macdonald wheel 510 Nov 30 09:17 .git -rw-r--r-- 1 riley.macdonald wheel 70966 Nov 22 10:19 .git-completion.bash -rw-r--r-- 1 riley.macdonald wheel 201 Nov 30 09:16 .gitconfig -rw-r--r-- 1 riley.macdonald wheel 0 Nov 17 17:11 .ideavimrc -rw-r--r-- 1 riley.macdonald wheel 9698 Nov 22 10:19 .vimrc -rw-r--r-- 1 riley.macdonald wheel 343 Nov 30 09:06 README.md |
These files contain all of my configurations organized into separate files. Using this approach I’m also able to version control and backup my configurations. If anything goes wrong I can roll back the changes or fix them while referencing a complete history.
Approach
I created a base ~/.bashrc
file that sources all of the bash stuff (aliases, exports, etc). I then source my ~/.bash_profile
to the ~/dotfiles/.bashrc
base file:
source /Users/riley.macdonald/dotfiles/.bashrc |
I follow the same approach for .vimrc
etc. For git I use the [include]
syntax (requires git 1.7.10+):
[include] path = /Users/riley.macdonald/dotfiles/.gitconfig |
Summary
As I continue to customize my development environment I just push to the remote. When I’m on a different machine I can just pull and run source ~/.bash_profile
and I’m good to go! Happy dotfiling!