Having a backup version of config file is a nice thing to have when you screw something up. It allows you to experiment with adding new stuff to the file without ending a day with not working tool.
You’ve probably seen people sharing their dotfiles on Github accounts or r/unixporn at Reddit using git repos. At least I’ve seen.
So my first trial of backuping my config files was very trivial (but it did the job!). I just cpied i3wm config to created directory, initiated a new git repository and pushed that to the remote repo on Github. And you might think that’s not bad!
Yeah, it’s not… but then I need to change something in the config, I’m doing it, i3wm works, so maybe that’s time for the git trio: add, commit, push? Nope, I had to cpied files again to the directory (where my git repo was initiated) and then do the trio.
Could it be a little bit easier? Yep
Symlinks
Few days ago I’ve (finally) decided to try to install some plugins for vim. And I thought, hmm…, maybe I should do backups of my .vimrc as I don’t now too much about configuring vim and if I get working .vimrc, I don’t want to lose it.
However I was like, well, I don’t update my i3wm configs too often and that’s because it’s not easy enough for me, so I need to find a better way of backuping .vimrc. So I used search engine and found out this post at opensource.com.
The author of the post shared his solution, in which he’s using a symlink.
But what’s the symlink?
It’s a file that points to other file or directory and it can be created with command ln - that’s what I know about symbolic links.
However it’s enough to make dotfiles’ backups easier!
So the solution for creating my .vimrc backup with git:
# creating directory
$ mkdir dotvim
$ cd dotvim
# init git repository
$ git init
# coping stuff here
$ cp ~/.vimrc .
# creating symlink, passed paths need to be absolute
$ ln -nfs /home/arek/dotvim/.vimrc /home/arek/.vimrc
What’s the benefit?
Now when I edit ~/.vimrc or ~/dotvim/.vimrc, both of them stay the same!
No more coping stuff from home to directory (with git repository), just cd dotvim and do the git command trio!