2

When you execute git init in a new directory or an existing directory, Git creates a .git directory, where almost all the contents of the Git store and operation are located in the directory.
If you want to back up or copy a library, basically copy this directory to other places.

And now, I just want to download .git directory include contents from GitHub:

  • I know the link like https://github.com/google/gson.git,
  • then I can download the .git files through Python language using request. (I don't want to pass by git long command)

How do I find the .git directory from GitHub or my private gitlib and how to download it?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Ruibin.Chow
  • 83
  • 1
  • 6
  • 1
    You can't do that, because the git server is designed to expect a git client speaking the git protocol. But you can use a library such as [GitPython](https://pypi.python.org/pypi/GitPython/) instead of forking `git clone`. – Dan Lowe Jan 21 '17 at 05:06
  • 1
    That is exactly what `git clone` is there for. So, what is your problem with it? – Klaus D. Jan 21 '17 at 05:24

1 Answers1

5

If you need only the .git content, you still need to use a git command:

git clone --bare https://github.com/<user>/<repo>

You will get a bare repo, one without working tree and only the .git content

See "Python way to clone a git repository" and gitpython-developers/GitPython

from git import Repo
Repo.clone_from(git_url, repo_dir, branch='master', bare=True)

With pygit2, use pygit2.clone_repository:

clone_repository(url, path, bare=True)
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    I have another question, when I using git clone --bare to get the .git but some project was too large, dont resume from break point, I know using git fetch can resume the process, but it just get the FETCH_HEAD. I want to just get the all of .git files but also can resume, Is there any good way to solve it? – Ruibin.Chow Jan 21 '17 at 15:23
  • 1
    @zruibin to my knowledge, you cannot resume a fetch for *one* repo (http://stackoverflow.com/a/29192890/6309). You can indeed, when a clone is interrupted, make a git fetch. It should be enough for your .git bare repo folder to get all its files. – VonC Jan 21 '17 at 16:21