Last active
December 19, 2023 18:56
-
-
Save teknoraver/ae5d8b3d7026ba6a00c0bde324374814 to your computer and use it in GitHub Desktop.
Fork repo locally
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ $# -ne 2 ]; then | |
echo "usage: ${0##*/} <source> <target>" | |
echo " clone 'source' to 'target' sharing objects" | |
exit 1 | |
fi | |
src=$1 | |
trg=$2 | |
if ! [ -d "$src/.git/objects" ]; then | |
echo "$src is not a git repository" | |
exit 1 | |
fi | |
branch=$(git -C "$src" branch --show-current) | |
remote=$(git -C "$src" config "branch.$branch.remote") | |
url=$(git -C "$src" config "remote.$remote.url") | |
git init -b "$branch" "$trg" | |
git -C "$trg" remote add "$remote" "$url" | |
realpath --relative-to="$trg/.git/objects" "$src/.git/objects" >"$trg/.git/objects/info/alternates" | |
git -C "$trg" fetch | |
git -C "$trg" checkout "$branch" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment