BACKUP AND RESTORE DOTFILES USING GIT
This article is about how to back up
dotfiles using Git. I will try to keep it short and straightforward.
Zsh as the shell in the examples, but another shell can be used. The commands below should be executed as a normal user in the
Create a local Git repository that will be used to track the
The default behaviour of Git commands is to run inside the project folder using information stored at the
<project>/.git directory and Git assumes that the working tree is located at
<project>. To enable the execution of Git commands specifically for the “dotfiles” repository from anywhere, it is needed to create an alias that indicates the location of the Git directory and the working tree.
Make this alias permanent.
aliases file inside the
.zshrc file by adding the following line.
By default, Git will consider all the files under the working tree as untracked. To avoid this behaviour, configure Git to show only the files that are explicitly added.
Add the files that you want to track, for example.
Link the local to the remote repository. The remote repository can be a GitHub or any other Git repository.
Push the changes to the remote repository. This is effectively the backup of the dotfiles.
Now the dotfiles are backed up to the remote repository.
To restore the dotfiles in a new system, clone the repository using the
Before checking out, ensure that none of the repository files exist in the local filesystem. If there are existing files, backup them by renaming them to something like
filename.old and then run the following command.
Close the terminal and re-open it. All the configurations should be enabled now as the dotfiles should be at the right places.
Job done! The files are now being backed up to GitHub and restored to the right place. Remember to use the
dotfiles alias when dealing with the dotfiles Git repository.