A dotfile
, named so because the file name commonly starts with ".
", is a file that contains user defined preferences and configurations for various programs in their development environment. Common dotfiles
are .zshrc
and .bashrc
, .vimrc
, .gitconfig
, .gitignore
, and files in the .config
directory.
Setting up dotfiles
that maximize efficiency and productivity is a time consuming and iterative process. A dotfiles
repo allows these settings to be safely backed up and quickly recovered in the event of catastrophic local hardware failure or just moving to new hardware.
Having a public dotfiles
repo is also an easy way for devs to share and explore alternate environment setups with others.
- Initialize a bare git repository:
$ git init --bare $HOME/.dotfiles
- In your
.zhrc
or.bashrc
, create an alias for updating your dotfiles repository. I usedot
because I'm lazy and not that creative:
# ~/.zshrc
alias dot="git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME"
You now have a git
like command exclusively for your dotfiles.
- Configure your repo to not show untracked files:
$ dot config --local status.showUntrackedFiles no
- Create a README.md file, then add it to your repo and commit. IMPORTANT NOTE: Never add new or changed files to your repo with
dot add .
, as this will attempt to stage EVERY file and directory in your$HOME
directory.
$ touch README.md
$ dot add README.md
$ dot status
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README.md
Untracked files not listed (use -u option to show untracked files)
$ dot commit -m "Initial commit"
- Set up a remote on GitHub and link it to your local repo:
$ dot remote add origin [email protected]:some-dev/dotfiles.git
$ dot remote -v
origin [email protected]:some-dev/dotfiles.git (fetch)
origin [email protected]:some-dev/dotfiles.git (push)
$ dot push -u origin main
Congratulations! You now have a dotfiles
repo!
As previously stated, avoid using dot add .
when adding new files and changes. Likewise, ALWAYS check your files to ensure they do not contain any secrets or tokens BEFORE you commit them.
If you use Homebrew
, you can quickly and easily create a Brewfile
, which is like a lock
file for software managed by homebrew
. Having a Brewfile
in your dotfiles repo will allow you to quickly reinstall dependency software when needed.
To create a Brewfile
, simply run brew bundle dump
in your $HOME
directory, then add it to your dotfiles
repo.
If they don't contain any secrets, .zshrc
and .bashrc
files can be added to your repo. If they do contain tokens or secrets, you can extract them into other, untracked files and import them into your rc files using source
syntax.
Below are some resources that I used to create this repo:
- The best way to store your dotfiles: A bare Git repository
- Ask HN: What do you use to manage dotfiles?
- This README
Brewfile resources: