ynu8xq
Last Updated: February 25, 2016
·
2.705K
· itseranga
892414 10151468467596730 1847316210 o

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_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

Picture

  • 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 https://github.com/erangaeb/dotfiles.git
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 - 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 README file

Installation

    git clone https://github.com/erangaeb/dotfiles.git ~/.dotfiles


Create symlinks

    ln -s ~/.dotfiles/zshrc ~/.zshrc
    ln -s ~/.dotfiles/bash_profile ~/.bash_profile
Say Thanks
Respond

3 Responses
Add your response

15942
D42a7264714dee5006b9c99d2567a320

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

over 1 year ago ·
15946
0d38ee92831618c24839dc002859c32f

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 ·
15947
892414 10151468467596730 1847316210 o

@dpashkevich Thanks :)

over 1 year ago ·
Filed Under