--- /dev/null
+#! /bin/sh
+set -e
+
+# To the top-level directory of the current submodule
+cd "`git rev-parse --show-toplevel`"
+
+unset GIT_DIR
+
+# If .git/ subdirectory is already here
+test -d .git && exit 0
+
+if ! test -f .git; then
+ echo "Error: Cannot find gitlink, aborting" >&2
+ exit 1
+fi
+
+# Fix core.worktree now
+git config --unset core.worktree
+
+read _gitdir gitpath < .git
+unset _gitdir
+rm .git
+exec mv "$gitpath" .git