Git: Root Tracking
Written: 08/06/2024
The Problem
I have multiple linux systems, each with it's own settings files and configuration. Tracking all of these systems manually is a headache. So I've decided to do the following:
  1. Create a git repository that tracks root (/).
  2. Change the branch name to the system in use.
  3. Manaully add the files i want to track.
  4. git push
The solution
      $ cd ~
$ mkdir root-settings-tracking
$ git init --separate-git-dir=./root-settings-tracking/.git /
# Repository now is at the home dir of the user
# while it's tracking the files from the root.
# This is so that the repository is not visible at every level in the whole system
# If we do `git status` from any directory.

# From here, we can access our git repository
$ cd /
# Change the branch name if you want
$ git branch -m BRANCH_NAME

# Understand the risks and why it needs to be done:
# https://github.com/git/git/commit/8959555cee7ec045958f9b6dd62e541affb7e7d9
$ git config --global --add safe.directory /

# We ignore every file in the system
$ echo "*" > /.gitignore

# Then we force add and track ignored files using -f
$ git add -f /home/any_file
$ git commit -m "Your message"
$ git remote add origin [YOUR_REMOTE_GIT]
$ git push 
    
Further reading
Stackoverflow Answer
$ git rev-parse --short HEAD
1597778