Search 

Manage “dotfiles” from anywhere with GIT

Nam Hoai Nguyen
Nam Hoai Nguyen
💡
This notes explains how to manage dotfiles using GIT.

What are Dotfiles?

Dotfiles is the name given to the set of hidden files used to store the state configuration or the preferences configuration of a tool.
The term “dotfiles” comes, like most things in computing, from the old Unix kernels that adopted the practice of adding the prefix . in front of the filename to make that file, by default, a hidden file, i.e., a file that is not shown in the listing for ls
As any Unix based system has a very strong relationship with files, since most modules and even devices or network interfaces are shown as files within the file system, they are highly important for software development.
Nowadays, the vast majority of tools use dotfiles to maintain configuration files:
  • Bash:.bashrc
  • Git: .gitconfig.gitexcludes
  • Vim:.vimrc

Why do we manage Dotfiles?

As a developer, I used to use both MacOS and Linux OS. It took time for me to setup more tools what I used with same configuration such as zsh, neovim, terminal,….
Before, I must be save a copy of “dotfiles” on some cloud storage like Dropbox or GDrive. It’s crazy. This is not problem as long as I only save one file. But what about when I start saving with multiple files? How to manage it from several programs, in several folders and worse, how to restore it all later? You can compress theme into zip file and upload them. Answer “NO”, we need a smarter way.

Managing Dotfiles

The idea of managing configuration files using git is make the configuration easier to segment and symlink to config file
Check the system is “Linux” or “Mac”
1echo $(uname -s)
2# Darwin (Mac)
3# Linux (Linux)
Applied configuration for special OS
1# .zshrc
2
3if [ $(uname) == "Darwin" ]; then
4	source ".profile-mac"
5fi
6
7if [ $(uname) == "Linux" ]; then
8	source ".profile-linux"
9fi
Create a symlink
1# create mapping for .config
2ln -s .cfg/.zshrc $HOME/.zshrc
When you updated config in .cfg/.zshrc , $HOME/.zshrc will update too