Dotfiles are those sneaky files in your home directory that start with a dot. Examples include .bashrc or .vimrc. Many users will never encounter these types of files because they generally don't show up in the file viewer. However, a quick ls -al in your home directory will reveal all the dotfiles you've created (or that have been created for you). As someone who talks to computers all day, these dotfiles are my bread and butter for keeping my working environment running smoothly and effortlessly.
More specifically, dotfiles are just text files that can store configurations and settings for the various programs used on the machine. For example, I like to use vim as my text editor sometimes, and I have it configured so that it looks and behaves a certain way every time I open it. There is a specific dotfile for vim in the home folder, called .vimrc, where I can store all of these configurations.
For me, the magic of dotfiles really shines through when they're stored in a public repository for all to see. First and foremost, I'm not just sharing these files with other people — I'm sharing them with my future self as well. So if I fry my motherboard with hot coffee or do a fresh install of Arch Linux for the millionth time, I don't have to lose all my beautiful vim configurations. I can just pull in the remote repository and get my working environment set up exactly the way it was. Secondly, sharing dotfiles is a great way for developers to communicate tips and tricks about the way they work every day without having to articulate it in plain English.
First I'll talk about how to store dotfiles in a remote repo, so that you can have your dev environment up and running seconds flat. Regardless of whether you're already using dotfiles, the process of adding them to a version control system is fundamentally the same.
git init --bare $HOME/.cfg
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
config config --local status.showUntrackedFiles no
echo "alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'" >> $HOME/.bashrc
config remote add origin email@example.com:my-username/my-new-repo-name.gitSince it's my first time pushing to this repo, I might need to set the upstream while I do so:
config push --set-upstream origin masterNow any file in my $HOME directory can be added to version control by using normal git commands, but using the alias that we created for git called config instead. For example, the following will add, commit, and push your local .bashrc file to the remote Github repository:
config status config add .bashrc config commit -m 'Add bashrc' config push
Now that all my dotfiles are in version control, any time I try out a new Linux distirbution or get a new computer, I can have my old environment at my fingertips in seconds. Try it out and let me know what you think!