Last Updated: February 25, 2016
·
4.641K
· mrkschan

Make symlink on Windows in a GIT repo

Starting from the tips shared on http://stackoverflow.com/a/16754068/433662, I come up with the following bash git-add-symlink to create symlink in a GIT repo using relative path.

#!/usr/bin/env bash

src=$1
dest=$2

if [[ "$src" == "" ]]
then
  bin=`basename $0`
  echo "Usage: $bin <src> <dest>"
  echo "<src> and <dest> are relative to pwd."
  exit 0
fi

prefix=`git rev-parse --show-prefix`
hash=`echo -n "$src" | git hash-object -w --stdin`

git update-index --add --cacheinfo 120000 "$hash" "$prefix$dest"
git checkout -- "$dest"

Now, we can run git add-symlink src dest to create symlink on Windows (src and dest are relative to pwd).

Enjoy!