This tutorial is about backing up the configuration under a user’s home directory using Git.
Git supports negation of patterns in .gitignore
files. To negate a
pattern we simply prefix it with !
. This feature enables to use
.gitignore
file in a user’s home directory that instructs Git to
ignore all files under this directory except the ones matching the
patterns prefixed with !
.
i.e.
################################################################################
# Ignore everything except what we want to back up (Note that / is the
# root of the repository and not the actual root of the filesystem
################################################################################
/*
################################################################################
# You definitely do not want to ignore your gitignore (:
################################################################################
!/.gitignore
################################################################################
# Files
################################################################################
!/.Xresources
!/Documents/zakkak.vcf
!/.zshrc
################################################################################
# Folders
################################################################################
!/.config/
/.config/*
!/.config/git/
!/.config/htop/
!/.fonts/
!/bin/
Note also that core.excludesfile
in the Git configuration must not
be set to ~/.gitignore
. Please check man git-config
to see how
you can accomplish this. In general it is advised to use
$HOME/.config/git/ignore
to set patterns to be globally ignored by
Git.
Now you can run git init
in the user’s home directory to initialize
a repository and the git add .
to stage all files not ignored by Git
based on the new .gitignore
. Then git remote add origin url/to/your/repo
and you can start tracking the user’s configuration
and push it upstream so you can sync it across different systems.