Skip to content

Instantly share code, notes, and snippets.

@simonw
Last active November 5, 2024 00:07
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"
@xingfeT
Copy link

xingfeT commented Jul 13, 2018

Wow

@luismartingil
Copy link

luismartingil commented Jul 20, 2018

Creating a tar file for all the tags of the repo

path=/Volumes/myfolder
repo=mygitrepo
for tag in `git tag | xargs`; do
	echo git archive --format=tar.gz -o $path/$repo-$tag.tar.gz --prefix=$repo-$tag/ $tag;
done

@purcell
Copy link

purcell commented Sep 12, 2019

This popped up as a result in a web search, so in case it's useful to anyone, I'll mention here that if the repo is on Github, you can also download a tarball of any repo directly, e.g.

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

and master can be any ref, e.g. a tag.

@easbarba
Copy link

easbarba commented Oct 10, 2019

@purcell

It would be clearer if projects compressed file named as 'repo-master.tar.gz', it is a disruptive annoyance by naming them like that.

Imagine one needing to download more than one project compressed file in a script. eg: me :D

@purcell
Copy link

purcell commented Oct 10, 2019

Well it's easy enough to specify a different output name, e.g. with wget's -o argument.

@irischad
Copy link

irischad commented Feb 27, 2020

This popped up as a result in a web search, so in case it's useful to anyone, I'll mention here that if the repo is on Github, you can also download a tarball of any repo directly, e.g.

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

and master can be any ref, e.g. a tag.

@purcell
This is the single most useful thing I've learned today. Already saving me so much time... Thanks!

@purcell
Copy link

purcell commented Feb 27, 2020

This is the single most useful thing I've learned today. Already saving me so much time... Thanks!

I know, right? Super handy. Happy tinkering!

@mhucka
Copy link

mhucka commented Jul 10, 2020

It may be worth mentioning here that for GitHub, there is also github-backup. It has options to capture GitHub-specific features like issues, wikis, and so on. (This is not meant to take away from the original answer or the utility of git archive. Also, I'm not associated with github-backup – just a satisfied user.)

@heymajor
Copy link

heymajor commented Aug 1, 2020

This popped up as a result in a web search, so in case it's useful to anyone, I'll mention here that if the repo is on Github, you can also download a tarball of any repo directly, e.g.

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

and master can be any ref, e.g. a tag.

🤯

@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

@yskelg
Copy link

yskelg 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.

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