Download Git repository content without .git/
Method 1: Shallow clone + remove .git/ (Recommended)
git clone --depth 1 <repository-url> <target-directory>
rm -rf <target-directory>/.git
- Pros: Works with any Git server (SSH, HTTPS, Git protocol). Fast (only fetches latest commit).
- Cons: Temporarily creates
.git/ before deletion.
Method 2: git archive (No .git/ created, but server-dependent)
git archive --remote=<repository-url> HEAD | tar -x -C <target-directory>
- Pros: Never creates
.git/.
- Cons: Requires the remote server to support
git archive (most public hosts do, but some private servers may not).
Example (Method 1)
git clone --depth 1 https://github.com/user/repo.git my-repo
rm -rf my-repo/.git
→ my-repo/ now contains only the files, no Git metadata.