dotfiles

My dotfiles management using git in Linux started with the atlassian article. It helped me move my desktop from Linux Mint to Arch and later to Alpine Linux reasonably smoothly.

Intially i maintained both the machine spefic config and user configuration in a single repo. Though i moved the repo from github to sr.ht by just changing the remote.

Once i started adding more machines, the need to maintain multiple repo’s for machines arose, which i wanted to avoid. Using claude, this migration has been completed.

Basic git configuration

Note that In every machine basic git configuration has to be done. After transferring both public and private key safely to the .ssh folder, issue the following commands.

git config --global user.name "Your Name"
git config --global user.email "mailid@mailprovider.com"
git config --global user.signingkey ~/.ssh/id_ed25519
ssh -T git@git.sr.ht # For github this is ssh -T git@github.com

First time configuration

Create bare repos using init command.

git init --bare $HOME/.dotfiles
git init --bare $HOME/.machine-config

set up aliases, depending on the shell used, add it to shell config file.

alias sysconfig='git --git-dir=$HOME/.machine-config --work-tree=/'
alias dotfiles='git --git-dir=$HOME/.dotfiles --work-tree=$HOME'

Adding alias for fish shell is shown.

echo "alias sysconfig='git --git-dir=/home/prabu/.machine-config --work-tree=/'" >> ~/.config/fish/config.fish
echo "alias dotfiles='git --git-dir=/home/prabu/.dotfiles --work-tree=$HOME'" >> ~/.config/fish/config.fish
source .config/fish/config.fish

Perform this basic housekeeping to avoid adding uneeded files to the repos.

sysconfig config status.showUntrackedFiles no
dotfiles config status.showUntrackedFiles no

Configure the repos after ensuring that the repo exists on the server of your choice. Here https://sr.ht ↗ is used.

sysconfig remote add origin git@git.sr.ht:~prabuanand/machine-config
dotfiles remote add origin git@git.sr.ht:~prabuanand/dotfiles

Repeat the add command for every file to track. Once all files are added, perform the following steps for commiting the pushing the user dotfiles.

dotfiles add /home/prabu/.profile
dotfiles status
dotfiles commit -m "added .profile"
dotfiles push origin master

Note the few additional steps performed to change the branch for the machine specific config files. Additional steps are given to verify the change.

sysconfig checkout -b machine/homepc2
sysconfig branch #verify the correct branch
sysconfig remote show origin # To verify if everything is in order

Repeat the add for every file to track. Perform the following steps similar to what was done for the user dotfiles.

sysconfig add /etc/fstab
sysconfig status
sysconfig commit -m "added /etc/fstab"
sysconfig push origin machine/homepc2

Reusing existing user dotfiles

The below steps explain how to reuse existing user dotfiles on a machine named oci.

Perform the following basic steps to create the bare repo and necessary alias and remotes.

git init --bare $HOME/.dotfiles
git init --bare $HOME/.machine-config
echo "alias dotfiles='git --git-dir=/home/prabu/.dotfiles --work-tree=$HOME'" >> ~/.config/fish/config.fish
echo "alias sysconfig='git --git-dir=/home/prabu/.machine-config --work-tree=/'" >> ~/.config/fish/config.fish
source ~/.config/fish/config.fish
dotfiles config status.showUntrackedFiles no
sysconfig config status.showUntrackedFiles no
dotfiles remote add origin git@git.sr.ht:~prabuanand/dotfiles
sysconfig remote add origin git@git.sr.ht:~prabuanand/machine-config

The below clone command could be used for repos like dotfiles instead of 3 commands to init, remote add and fetch commands shown above. The steps related to alias and housekeeping are still needed.

git clone --bare git@git.sr.ht:~prabuanand/dotfiles $HOME/.dotfiles

Fetch the files from above remote.

dotfiles fetch origin

Backup existing conflicting files. Without this step, checkout will error on existing files.

mkdir $HOME/.dotfiles-backup
dotfiles checkout master 2>&1 | grep "^\t" | sed 's/^\t//' | \
  xargs -I{} mv $HOME/{} $HOME/.dotfiles-backup/{}

To checkout the entire dotfiles repo, issue the command.

dotfiles checkout master

Machine-config files on new machines

For machine config file management, Create new machine branch for oci.

sysconfig checkout -b machine/oci

The machine config files can either differ totaly from existing machines or based on an existing one.

Creating new machine-config files

The following steps are for the case where machine-config files differ totally from other machines. Repeat the add for every file that needs tracking on the oci machine.

sysconfig add /etc/fstab
sysconfig commit -m "initial commit: oci"
sysconfig push origin machine/oci

Reusing existing machine-config files

To use machine-config file from another machine’s configuration fetch + cherry-pick to use latest version of a file

sysconfig fetch origin
doas git --git-dir=$HOME/.machine-config --work-tree=/ checkout origin/machine/homepc2 -- /etc/resolvconf.conf

Handling doas

To remove systemfiles, need to use doas with full git command as alias won’t work.

doas git --git-dir=$HOME/.machine-config --work-tree=/ rm /usr/local/bin/current_song.sh

Handling machine-config entirely using doas

Inital configurtion

Run the below commands once.

Fix the permission before beginning:

doas chmod 700 /home/prabu/.machine-config

Set the permanent Alias in your shell config:

alias sysconfig='doas git --git-dir=/home/prabu/.machine-config --work-tree=/'

Ensure that the identity and SSH settings are configured into the repo config:

sysconfig config user.name "Prabu Anand Kalivaradhan"
sysconfig config user.email "kprabuanand@gmail.com"
sysconfig config core.sshCommand "ssh -i /home/prabu/.ssh/id_ed25519 -o UserKnownHostsFile=/home/prabu/.ssh/known_hosts"

Verification commands:

Verify the config file of any git:

doas cat /home/prabu/.machine-config/config

Verify the identify shown in commit:

sysconfig log -1

verify core.sshCommand using git:

sysconfig config core.sshCommand

Correction commands

Rewrite the last commit with the correct author:

sysconfig commit --amend --reset-author --no-edit

“do-over” last commit:

sysconfig commit --amend --no-edit

Migration steps from combined user + machine config

If you are starting new, this section can be ignored.

Initially i kept my bare git in $HOME/.systemfiles folder. For my case i need to carve user config out of what is currently a machine repo. So i copied over my existing bare git repo from ‘.systemfiles’ to ‘.machine-config’.

cd /
sysconfig ls-files / > /home/prabu/test #cleanup the file to remove machine-config files
head -n 5 /home/prabu/test
home/prabu/.ash_aliases
home/prabu/.ashrc
home/prabu/.bash_profile
home/prabu/.bashrc
home/prabu/.config/chrome-flags.conf
sed 's|^home/prabu|/home/prabu|' /home/prabu/test | xargs git --git-dir=$HOME/.dotfiles --work-tree=$HOME add
dotfiles commit -m "initial commit: user dotfiles migrated from https://git.sr.ht/~prabuanand/machine-config"
dotfiles push --force origin master
sysconfig ls-files / > /home/prabu/test #cleanup the file to keep unwanted user dotfiles
sed 's|^home/prabu|/home/prabu|' /home/prabu/test | xargs git --git-dir=$HOME/.machine-config --work-tree=/ rm --cached
sysconfig commit -m "removed dotfiles, now tracked in https://git.sr.ht/~prabuanand/dotfiles repo"

Sources


© Prabu Anand K 2020-2026