Symlink dotfiles

There is a better solution for managing dotfiles without using symlinks or any other tool, just a git repo initialized with --bare.

A bare repository is special in a way that they omit working directory, so you can create your repo anywhere and set the --work-tree=$HOME then you don't need to do any work to maintain it.

Approach

first thing to do is, create a bare repo

git init --bare $HOME/.dotfiles

To use this bare repo, you need to specify --git-dir=$HOME/.dotfiles/ and --work-tree=$HOME, better is to create an alias

alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME

At this point, all your configuration files are being tracked, and you can easily use the newly registered dotfiles command to manage the repository, ex :-

# to check the status of the tracked and untracked files 
dotfiles status

# to add a file 
dotfiles commit .tmux.conf -m ".tmux.conf added"

# push new files or changes to the github
dotfiles push origin main

I also use this way to sync and store my dotfiles, see my dotfiles repository and can read at Storing dotfiles with Git where I wrote about managing for multiple devices.


That error message means that you already have a file at ~/.vimrc, which ln is refusing to overwrite. Either delete the ~/.vimrc and run ln again or let ln delete it for you by passing the -f option:

ln -s -f ~/dotfiles/.vimrc ~/.vimrc