Last active
December 10, 2025 07:19
-
-
Save kairyou/e49857f7e85da1e5869d21a9c04a4674 to your computer and use it in GitHub Desktop.
git-archive-all
This file contains hidden or 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
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
git archive with submodules
e.g.
curl -sL https://gist.githubusercontent.com/kairyou/e49857f7e85da1e5869d21a9c04a4674/raw/git-archive-all | bash -s -- https://github.com/Tencent/tdesign-react.gitcurl -sL https://gist.githubusercontent.com/kairyou/e49857f7e85da1e5869d21a9c04a4674/raw/git-archive-all | bash -s -- https://github.com/Tencent/tdesign-react.git main