36

I usually use the command below inside my project.git to get an archive in the specified destinations:

git archive master | tar -x -C /home/kave/site/

I wonder if its possible to archive directly from a remote repository instead into a destination directory?

I tried something like this, without any joy:

git archive master https://kave@dndigital.git.cloudforge.com/myoproject.git | tar -x -C /home/kave/site/

Any suggestions? Thanks

Houman
  • 64,245
  • 87
  • 278
  • 460
  • Git 1.9/2.0 (Q1 2014) will be much more efficient with shallow cloning: http://stackoverflow.com/a/21217267/6309 and http://stackoverflow.com/a/21217326/6309 – VonC Jan 19 '14 at 13:29
  • For GitHub repositories, you might consider [`gh repo archive `](https://stackoverflow.com/a/69576856/6309). – VonC Oct 14 '21 at 20:17

2 Answers2

43

From git help archive:

   --remote=<repo>
       Instead of making a tar archive from the local repository, retrieve a tar archive from a remote repository.

Command should end up like:

$ git archive --remote=https://kave@dndigital.git.cloudforge.com/myoproject.git master

But, if you would just extract the repo, you can make a shallow clone using --depth parameter of git clone:

   --depth <depth>
       Create a shallow clone with a history truncated to the specified number of revisions. A shallow repository has a number of limitations (you cannot clone or fetch from it, nor push from nor into it), but is adequate if you are only interested in the recent history of a large project with a long history, and would want to send in fixes as patches.

So you have something like this:

$ git clone --depth=1 https://kave@dndigital.git.cloudforge.com/myoproject.git
mwfearnley
  • 3,303
  • 2
  • 34
  • 35
mgarciaisaia
  • 14,521
  • 8
  • 57
  • 81
  • How can I make `git clone --depth=1` pull a specific tag instead of master? – robru Feb 21 '14 at 18:30
  • 7
    @Robru: That deserves to be a standalone question, I think, but read about `--[no-]single-branch` in `git help clone`. Something like `git clone --depth=1 --single-branch --branch TARGET_BRANCH REMOTE_URL`, I think. And, thanks - I've never thought about that before :) – mgarciaisaia Feb 21 '14 at 22:02
  • 7
    Can't archive from Github: `You appear to be using ssh to clone a git:// URL.` You can look up this [article](https://www.gilesorr.com/blog/git-archive-github.html) for more details. – Cloud May 30 '18 at 00:53
  • 3
    You might also get an error `fatal: operation not supported by protocol` when trying to archive from Github over HTTP. The solution is the same as in the article linked by @SiminJie : Github offers a tarball download service, so use that. – Guss Apr 20 '20 at 10:14
1

Another option, specifically for GitHub, is github-backup. It has options to capture GitHub-specific features like issues, wikis, and so on. Here is an example command-line I used recently to make archives of some other people's repositories:

github-backup --all --pull-details --prefer-ssh --repository REPO REPO-OWNER -u mhucka

In the command above, REPO-OWNER stands for the owner of the target repository and REPO is the repository name.

mhucka
  • 2,143
  • 26
  • 41