Dotfiles
I briefly mentioned dotfiles in my last blog post. In this post, I want to go a bit deeper into dotfiles. We will also talk about using stow for symlinks.
Dotfiles
Dotfiles are configuration files that are hidden and start with a dot. These files (if there are no saved passwords) can be stored in a git repository and can be cloned on any machine. One of the use case is having the same setup / configurations across multpile machines
Dotfiles typically resides in the user home folder. If you want to version control these, you will have to make your home folder a git repo and use .gitignore
to ignore all files other than the specific files of your interest. This is how I started. Then I found a solution using stow, where the files could be anywhere on the machine, and I can create a symlink for these files and folders to the required location (home in this case)
Stow
A symlink is a symbolic Linux/ UNIX link that points to another file or folder on your computer, or a connected file system. This is similar to a Windows shortcut. Stow is a symlink farm manager which takes distinct packages of software and/or data located in separate directories on the filesystem, and makes them appear to be installed in the same place. You can use stow to create symlinks for your dotfiles. You can read more about stow here and here
Install stow with:
brew install stow
Creating Dotfiles Repository from sctarch
The simple use case where you are creating all the required files is shown in the last blog. Let us take a look at a case where we have git submodules. I am using the example of Tmux where I am using sub modules from other git repos
- Create a git repository on github called dotfiles
- Clone the repository to your local machine
git clone <repo-url>
- Change directory to dotfiles
cd ~/dotfiles
- For Tmux
- Create a folder called
tmux
mkdir tmux
- Change directory to tmux
cd tmux
- Move the tmux.conf file to tmux folder
mv ~/.tmux.conf .
- Add a tmux plugin (tpm is shown for example only)
mkdir .tmux/plugins
cd .tmux/plugins
git submodule add https://github.com/tmux-plugins/tpm
- Move to dotfiles folder
cd ../../..
- Create a symlink for tmux
stow tmux
- Create a folder called
- Check git status
git status
- You will find a new
.gitmodules
file and atpm
in the repo - Note that tpm is a submodule
- You will find a new
- Add and commit the changes
git add . && git commit -m "Basic dotfiles setup"
- Push the changes to a remote repository
git push
Reusing the Dotfiles repository on a new machine
- Clone the dotfiles repository
git clone --recurse-submodules <repo-url> ~/dotfiles
- Change directory to dotfiles
cd ~/dotfiles
- Create a symlink for tmux
stow tmux