Skip to content

Instantly share code, notes, and snippets.

@simonw
Last active April 16, 2025 15:21
Show Gist options
  • Save simonw/a44af92b4b255981161eacc304417368 to your computer and use it in GitHub Desktop.
Save simonw/a44af92b4b255981161eacc304417368 to your computer and use it in GitHub Desktop.
How to create a tarball of a git repository using "git archive"
@deRooij
Copy link

deRooij commented Nov 18, 2021

Just putting this here, it's not ideal but if you have a private repo and just want to fetch it:
Generate GitHub access token: https://github.com/settings/tokens
And use token like this:
https://<personal_token>:@github.com/<your_repo>/archive/main.tar.gz

It's no ideal solution as you will have to recreate the token over time and each dev who wants to use the repo needs their own token.

@forty
Copy link

forty commented Nov 15, 2022

This works on git repositories that are not Github

git archive --format=tar.gz -o my-repo.tar.gz --remote=git://sourceware.org/git/glibc.git master

Note that it doesn't work on Github as it appears it doesn't support it isaacs/github#554

@amidevous
Copy link

for subfolder not work please solve download github subfolder project

example

wget https://github.com/User/repo/archive/master/folder.tar.gz

not work return 404 error please solve or propose solution for work

download github subfolder project in tarball

thank you

@kzall0c
Copy link

kzall0c commented Jun 30, 2024

This solution available.

wget https://github.com/torvalds/linux/archive/refs/heads/master.zip

This previous solution was not available(why?)

$ wget https://github.com/User/repo/archive/master.tar.gz
--2024-06-30 15:22:42--  https://github.com/User/repo/archive/master.tar.gz
Resolving github.com (github.com)... 20.200.245.247
Connecting to github.com (github.com)|20.200.245.247|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2024-06-30 15:22:42 ERROR 404: Not Found.

@winston0410
Copy link

Git 2.44 or above support HTTP protocol for git archive, so you can probably create an archive from remote directly.

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