git export from github remote repository

GitGithub

Git Problem Overview


I'd like to export from github remote repository, not cloning it. Similar to svn export, I do not want to get .git folder with it. I can work around it by cloning and removing .git folder. I wonder if there is a cleaner way?

I read it somewhere you can use git archive to achieve this.

However I got the following errors..

$ git archive --format=tar --remote=git@github.com:xxx/yyy.git master | tar -xf -

Invalid command: 'git-upload-archive 'xxx/yyy.git''
You appear to be using ssh to clone a git:// URL.
Make sure your core.gitProxy config option and the
GIT_PROXY_COMMAND environment variable are NOT set.
fatal: The remote end hung up unexpectedly

Any help would be great. Thanks.

Git Solutions


Solution 1 - Git

Thanks to the Subversion support by GitHub, you can use svn export to get the project without any version control files:

svn export https://github.com/user/project/trunk

Notice the URL format:

  • The base URL is https://github.com/
  • USERNAME/PROJECTNAME without .git
  • /trunk appended at the end

This way you can get branches and subdirectories too.

This creates a directory with the exported files. It's not possible to create a tar/zip directly, you have to do in two steps (export + zip). This is a limitation of svn export itself.

As @Jon pointed out, this will create the export in a directory named trunk by default. You can specify a different name if you prefer:

svn export https://github.com/username/projectname/trunk projectname

You can use this technique to export any sub-directory of the project. For example if you want only some/path, you can do:

svn export https://github.com/username/projectname/trunk/some/path local-dir-name

You can get paths from branches and tags too. The endpoint https://github.com/username/projectname behaves fully as a Subversion repository with a regular layout, so you will find branches in https://github.com/username/projectname/branches and tags in https://github.com/username/projectname/tags.

Before you export something large by mistake, it's good to check first the content of the path. You can do that using svn ls, for example:

svn ls https://github.com/username/projectname/

Normally this should give you:

branches/
tags/
trunk/

You could iteratively explore the repository this way.

Solution 2 - Git

For unknown (to me at least) reasons GitHub doesn't support this.

We don’t support people running git-archive against our servers.

Seems silly, since via SVN you can, but... I upvoted @Janos' answer.

Solution 3 - Git

If your goal is to limit the quantity of information exchanged with the server, have you considered using clone with --depth? You would still need to remove the (much reduced) .git subdirectory though:

git clone --depth=1 [email protected]:xxx/yyy.git && rm -rf yyy/.git

Solution 4 - Git

If you're only interested in exporting from GitHub then they provide a mechanism to download tarballs. For example:

https://github.com/torvalds/linux/downloads

Even though it says "there aren't any downloads for this repository." you can still use the buttons to download a tarball of the master branch.

Or see this link for a list of tarballs linked to tags:

https://github.com/torvalds/linux/tags

This should work for any GitHub repo, not just the linux kernel.

Solution 5 - Git

If you need this for named commits (that is branches and tags), then you can use git clone --depth=1 combined with git archive

It is worth knowing that git clone --depth=1 clones all top commits on all branches and tags (not only master). So after doing such a shallow clone you can enter the local directory and make a git archive --format=tar tag_to_be_exported.

So if you want to export the tag release1.1

git clone --depth=1 [email protected]:xxx/yyy.git
cd yyy
git archive --format=tar release1.1 -o release1.1.tar

So unnless you need to export unnamed commit-ids, this may be a good solution.

Solution 6 - Git

I think it is not possible to export github repository with git archive. Please read this

https://help.github.com/articles/can-i-archive-a-repository

Only possible ways are

git clone  
github download (ZIP) button   

Solution 7 - Git

I ran into this same problem before, and AFAICT, it only seems to work with Bitbucket, e.g.

ysim:~/repos$ git archive --format=tar --prefix=alembic/ --remote=ssh://[email protected]/zzzeek/alembic.git master | tar -xf -
ysim:~/repos$ ls
alembic

But I found a workaround for GitHub using wget - so in the new GitHub interface, you'll find a button that says "Download ZIP" on the bottom of the right sidebar; right-click on it and copy the link address.

Download ZIP

Next, in the command line (I got the idea from here):

wget -qO- -O tmp.zip <zipball url> && unzip tmp.zip && rm tmp.zip

That will unzip it to a directory called something like repo-master/.

If you want, you can also alias this in your .gitconfig so you don't have to remember/type all of that out, e.g.

export = "! f() { wget -qO- -O tmp.zip \"$1\" && unzip tmp.zip && rm tmp.zip; }; f"

So you can just do something like this in the shell:

ysim:~/repos$ git export https://github.com/ysim/verbinski/archive/master.zip
ysim:~/repos$ ls
verbinski-master

Solution 8 - Git

One way to achieve this is to use the SVN support offered by GIT.

Steps to perform as root one off are (for Cent os);

yum install git
 
yum install subversion

Then to do a selective export the following syntax should be used:

svn export  <git repository>/<source folder> <empty target folder>  --no-auth-cache --force --username <active directory username>

If you do not use parameter --no-auth-cache when prompted to save the password type "no" for security reasons, or it will be saved unencrypted.

When translating from the GIT notation to the SVN notation the following mapping applies; replace "tree/master" with "trunk" for master replace "tree/branch_name" with "branches/branch_name" for branches

This works for both files and directories.

Solution 9 - Git

If you need to get a tarball of a commit on github I think this is the easiest way:

Say your repository name is https://github.com/arielgabizon/librustzcash

and the commit id is 4be41ca6160c16abfd983c8c878b6ea04105b224

Just go in your browser to the address https://github.com/arielgabizon/librustzcash/archive/4be41ca6160c16abfd983c8c878b6ea04105b224.tar.gz

and, at least on google chrome, it will start downloading the file.

Solution 10 - Git

For a normal export:

$ git archive master | tar -x -C /path/to/destination

For a zip archive:

$ git archive --format zip --output /path/to/destination/file.zip master

Of course for this to work, you'll need to clone it locally first, there's no clean way around that.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAdrian GunawanView Question on Stackoverflow
Solution 1 - GitjanosView Answer on Stackoverflow
Solution 2 - GitLAFK says Reinstate MonicaView Answer on Stackoverflow
Solution 3 - GitSamuel TardieuView Answer on Stackoverflow
Solution 4 - GitrathersView Answer on Stackoverflow
Solution 5 - GitJarlView Answer on Stackoverflow
Solution 6 - GitGihan De SilvaView Answer on Stackoverflow
Solution 7 - Git3cheesewheelView Answer on Stackoverflow
Solution 8 - GitAntoView Answer on Stackoverflow
Solution 9 - GitAriel GabizonView Answer on Stackoverflow
Solution 10 - GitMarvin PintoView Answer on Stackoverflow