M BUZZ CRAZE NEWS
// news

Commit symlink outside of repo to git

By Daniel Rodriguez

I have a repository with a backup of various config files. I would like the repo to contain only symlinks to the real config files (which are outside of the repository), so that I don't need to manually copy the config to repo in case of any changes.

When I tried to push symlink, the file was naturally unreadable in git or on other filesystem. Is there any way to force git to always follow the link and push original file, or is there any other approach?

1

2 Answers

I can think of two solutions:

Reverse the Direction of the Symbolic Link

Put the configuration file in your Git repository and make a symlink to that file as the actual configuration used.

Use a Hard Link

If the Git repository is in the same file system as the configuration location, instead of ln -s, use ln to make a hard link so that the configuration used and the Git working directory file refer to the same file.

2

This answer is based on this great tutorial.

The trick is to use a bare repository. This way you can leave your dotfiles where they belong and at the same time keep track of them using git:

# Init repo
git init --bare ${HOME}/.config.git
# Create a config alias for interacting with this repo and
# add it to your .bashrc for convenience
echo "alias config='/usr/bin/git --git-dir=${HOME}/. --work-tree=${HOME}'" >> ${HOME}/.bashrc && source ${HOME}/.bashrc
# Ignore all files except the ones you want to track
config config --local status.showUntrackedFiles no
# Start using your repo to track your dotfiles
config add ~/.bashrc ~/.vimrc ...

Head over to for more info on this.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy