开发者

Make a local copy of a remote git repository

I am not very familiar with the terminology or practices and procedures of version control.

Here is what I want to do :

  1. I want to download a folder from a git repository from the Internet. Is cloning the right way to do it ? WOn't cloning keep the unnecessary meta-data files ? Is there a way to do a "clean" download ?

  2. I want to set up a local repository that contains this folder on which I can now use version control. That is, when I do a commit, my local repository gets updated.

  3. Finally, I want this local repo to be accessible on t开发者_开发技巧he local network, so that I can download it from any other machine on the LAN too.


  1. Cloning is the right way, but will download all the directories of your remote Git repo.
    See git clone of Git Reference.
  2. The clone command will create a repo with a working tree already checked out in it, and a .git representing your full repo
  3. You need to have at least a shared path in order for other to clone/pull/push your repo.
    See git local protocol.

If you are not familiar with those operations, I would recommend you to follow the simple exercices proposed by git immersion.


You can't download single files or folders from a git repo, since git tracks the full state of a project as a whole, not just single files. There is a possibility to clone only a limited set of revisions (called shallow clone) from a remote repositoy, but such clones are restricted to a limited set of operations, for example you can't clone from a shallow clone, or push something from such a repo.

If the size of a git repo bothers you, you can git gc to make git reorganize the object database, which sometimes can get size improvements.

When you want to have a local cache, you can use git clone --mirror $REMOTE_URL to create a clone, which

  • tracks all remote branches (see What's the difference between git clone --mirror and git clone --bare)
  • is a bare repo (=has no working copy, see gitready.com or this SO question why this is a good idea for a cache repo)
  • act as a local cache, or a staging repo

You can clone new working repos from this local cache repo, and either push directly into the upstream repo (you need to git remote add upstream $REMOTE_URL in your working copy to add the link to the upstream repo, afterwards you can git push upstream), or you can push into the local cache repo, and push to the upstream repo from there.


While git clone is the right for steps 1 & 2, you may need to have a read of a few of the git books e.g. Progit / Community book etc. to get a proper flavour of the best approach to step 3, and the git philosophy.

Git, as a distributed VCS, tries hard to avoid the "single central repository" that your "local repo to be accessible on the local network" might suggest. You can have a bare repo on the network, which allows many to push/pull from it, but this isn't the same as having your local repo on the network, with working directory, and only you using it as if it were a local drive.


Yes 'git clone' is the way to go. This will get you all the data and allow you to do commits. As long as the new repo is visible on the LAN, other computers should be able to clone from it as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜