Skip to content

Instantly share code, notes, and snippets.

@kairyou
Last active December 10, 2025 07:19
Show Gist options
  • Select an option

  • Save kairyou/e49857f7e85da1e5869d21a9c04a4674 to your computer and use it in GitHub Desktop.

Select an option

Save kairyou/e49857f7e85da1e5869d21a9c04a4674 to your computer and use it in GitHub Desktop.
git-archive-all
#!/usr/bin/env sh
set -e
[ $# -ge 1 ] || { echo "usage: $0 <repo-url> [branch]"; exit 1; }
repo="$1"
branch="${2:-}"
name=$(basename "$repo" .git)
archive="${name}.tar.gz"
if [ -n "$branch" ]; then
git clone --branch "$branch" --single-branch "$repo" "$name"
else
git clone "$repo" "$name"
fi
( cd "$name" && git submodule update --init --recursive )
tar --exclude='.git' -czf "$archive" -C "$name" .
echo "Created $(pwd)/$archive"
prompt="Remove cloned directory '$name'? [Y/n] "
if [ -t 0 ]; then
read -r -p "$prompt" answer
elif [ -r /dev/tty ]; then
printf "%s" "$prompt" >/dev/tty
read -r answer </dev/tty
else
answer=Y
echo "Non-interactive shell detected; removing '$name' by default"
fi
answer=${answer:-Y}
case $answer in
[Yy]* ) rm -rf "$name" && echo "Removed $name" ;;
* ) echo "Left $name in place" ;;
esac
@kairyou
Copy link
Author

kairyou commented Nov 11, 2025

git archive with submodules

curl -sL https://gist.githubusercontent.com/kairyou/e49857f7e85da1e5869d21a9c04a4674/raw/git-archive-all | bash -s -- <repo-url>

e.g.

  • curl -sL https://gist.githubusercontent.com/kairyou/e49857f7e85da1e5869d21a9c04a4674/raw/git-archive-all | bash -s -- https://github.com/Tencent/tdesign-react.git
  • curl -sL https://gist.githubusercontent.com/kairyou/e49857f7e85da1e5869d21a9c04a4674/raw/git-archive-all | bash -s -- https://github.com/Tencent/tdesign-react.git main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment