Disclaimer: there are other proven solutions to the problem. I do think the technique below is very elegant though.
What's git?
Git is a distributed version control system that tracks versions of files. It is often used to control source code by programmers who are developing software collaboratively.
Git can also be used to track the dotfiles of your system, by using the proper flags.
Git was originally created by Linus Torvalds for version control during the development of the Linux kernel.
Creating a git bare repository
If you haven't set up a git bare repository yet, let's make one.
git init --bare $HOME/dots
alias config='/usr/bin/git --git-dir=$HOME/dots/ --work-tree=$HOME'
config config --local status.showUntrackedFiles no
echo "alias config='/usr/bin/git --git-dir=$HOME/dots/ --work-tree=$HOME'" >> $HOME/.bashrc
The initial step involves creating a folder '~/dots', which serves as a Git bare repository to monitor our files.
Next, we establish an alias named 'config', which will replace the standard git command when interacting with our configuration repository.
We apply a '--local' flag to the repository to conceal files that are not yet explicitly tracked.
This ensures that when you execute config status and other commands later, files you do not wish to track will not appear as untracked.
You can manually add the alias definition to your .bashrc, or you can use the fourth line provided for convenience.
Interacting with the git bare repository
After you've executed the setup any file within the $HOME folder can be versioned with normal commands, replacing git with your newly created config alias, like:
config status
config add .vimrc
config commit -m "Add vimrc"
config add .bashrc
config commit -m "Add bashrc"
config push
The first line show the status of the repo, listing unstaged files, if any.
The second line add 'vimrc' to the files that are tracked by the repo.
The third line allows us to commit the change(s) to the repo with the message "Add vimrc"
Commit messages can be added using the -m flag.
The fourth line add the '.bashrc' to the files that are tracked by the repo.
The fifth line allows us to commit the change to the repo with the message "Add bashrc"
The sixth line will push all the changes to the repo.
What's next?
In Part 2 I will show you how to install the dot files to a new setup and to migrate this setup on a server.
Comments