Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a local copy of a remote git repository

Tags:

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 the local network, so that I can download it from any other machine on the LAN too.

like image 781
AnkurVj Avatar asked Aug 20 '11 08:08

AnkurVj


People also ask

How do I clone a git repository to a local folder?

To clone git repository into a specific folder, you can use -C <path> parameter, e.g. Although it'll still create a whatever folder on top of it, so to clone the content of the repository into current directory, use the following syntax: cd /httpdocs git clone [email protected]:whatever .

What is a local copy of a remote repository called?

When you clone a repository initially to get it onto your computer, you copy the entire repository from a remote location to your local computer. During this processes, git will add a remote to your local copy of the repository called origin . This will point to the location of the repository that you cloned from.


2 Answers

  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.

like image 130
VonC Avatar answered Sep 21 '22 07:09

VonC


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.

like image 37
foobar Avatar answered Sep 21 '22 07:09

foobar