Keep your dotfiles in git
What are dot files
- Dot files are hidden files. You have configured a lot of your own settings, configurations, or themes within dotfiles. Following are some example dot files
~/.vimrc
~/.bashrc
~/.bash_profile
~/.zshrc
Purpose of keeping dot files in git
When you switching between machines(for example move to new machine) it can be difficult to keep your configuration files synchronized across them
One solution is to put your dot files under version control
By storing your dotfiles in a Git repository, you’ll be able to use them on any OS X or Linux machine with Internet access
In this example I'm gonna keep my
.bash_profileand.zshrcin git repository ingithub.
How to do that??
- Create folder call
~/.dotfilesin your home directory (its a hidden directory)
mkdir ~/.dotfiles
- Move your
~/.bash_profileand~/.zshrcfiles to~/.dotfiles
mv ~/.bash_profile ~/.dotfiles/bash_profile
mv ~/.zshrc ~/.dotfiles/zshrc
Note that the files in ~/.dotfiles directory are not hidden(not with . prefix )
- Create symlinks to moved files
ln -s ~/.dotfiles/zshrc ~/.zshrc
ln -s ~/.dotfiles/bash_profile ~/.bash_profile
- Create github repository(In my scenario I have created repo name
dotfiles). After creating the repository, github direct you how to push files to it

- According to the instructions I have made my local
~/.dotfilesdirectory as a git repository and commit the changes
cd ~/.dotfiles
git init
git add bash_profile
git add zshrc
git commit -m "initial dot files"
- Configure your
git remoteconfigurations in your local git repository and push the changes to thegithub
git remote add origin https://github.com/erangaeb/dotfiles.git
git push -u origin master
- You are done :) .. you can add more configuration files to
.dotfilesdirectory and keep them ingithub
This is my github repository - https://github.com/erangaeb/dotfiles
Install your dot files in another machine
Once your configuration files(dot files) is under version control, it’s quite straightforward to import your settings to any machine that has git installed
I have added the instruction in
READMEfile
Installation
git clone https://github.com/erangaeb/dotfiles.git ~/.dotfiles
Create symlinks
ln -s ~/.dotfiles/zshrc ~/.zshrc
ln -s ~/.dotfiles/bash_profile ~/.bash_profileWritten by eranga bandara
Related protips
3 Responses
You can create a small install script for your dotfiles that will create symlinks and possibly do other stuff. Here's mine:
https://github.com/dpashkevich/dotfiles/blob/master/cli/install.sh
The other thing is to be careful what info you add, e.g. you don't want to share your ssh keys on github.
@dpashkevich Thanks :)