Reputation: 93
I'm using Google's git-repo plugin. According to my understanding repo sync
will download the whole source code (i.e. previous revisions) from the repository. That is why it is taking a lot of time to complete this whole process.
Can we download only the latest commit from the repository?
Upvotes: 3
Views: 11901
Reputation: 47062
I don't use repo, but it appears that you can pass the --depth
flag to repo init
. Using something like repo init -u URL --depth=1
. The depth flag gets passed to git-clone
and create a repo with only part of the history:
--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.
Upvotes: 5
Reputation: 19475
Yes, by default git fetch
(which is part of what git clone
does) will fetch
the complete history of the remote repository.
You can limit the amount of history that is retrieved by using the --depth
option of the fetch command (clone will pass that on to fetch). To retrieve the
minimal amount of history you could use:
git clone --depth 1 REPO_URL
This would retrieve the latest commit and the one(s) immediately preceding it, but not older commits. It isn't possible to retrieve just the latest commit, since a depth of 0 is taken as wanting the full history; but this is close.
Later you can use git fetch
with a larger depth to increase the amount of
available history, or use git fetch --unshallow
to retrieve the complete
history.
There are currently a number of limitations on shallow repositories. The
docs for git clone --depth
say:
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.
Although there has recently been work on reducing or perhaps even removing those limitations.
Upvotes: 2
Reputation: 6410
What you are looking for is probably git pull
See the docs. You first need to add your github repository as a remote host:
git remote add master [email protected]:username/repository.git
Afterwards you can pull from the repository. On github there is also a link to download any commit as a .zip
file. Format for that is usually:
https://github.com/username/repository/archive/master.zip
Upvotes: 0