Last Updated: September 29, 2021
· itseranga

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

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_profile and .zshrc in git repository in github.

How to do that??

  • Create folder call ~/.dotfiles in your home directory (its a hidden directory)
mkdir ~/.dotfiles
  • Move your ~/.bash_profile and ~/.zshrc files 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 ~/.dotfiles directory 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 remote configurations in your local git repository and push the changes to the github
git remote add origin
git push -u origin master
  • You are done :) .. you can add more configuration files to .dotfiles directory and keep them in github

This is my github repository -

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 README file


    git clone ~/.dotfiles

Create symlinks

    ln -s ~/.dotfiles/zshrc ~/.zshrc
    ln -s ~/.dotfiles/bash_profile ~/.bash_profile

3 Responses
Add your response

You can create a small install script for your dotfiles that will create symlinks and possibly do other stuff. Here's mine:

over 1 year ago ·

The other thing is to be careful what info you add, e.g. you don't want to share your ssh keys on github.

over 1 year ago ·

@dpashkevich Thanks :)

over 1 year ago ·