Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to git clone a specific tag only without getting the whole repo?

Tags:

git

git-clone

I want to get linux kernel 2.6.22.19 source for cross compiling stuff for my router, but the repo is huge (3gb) if I do

git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git

and then check out that tag, the clone took forever, my bandwidth is limited.

if I run this

git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git --branch v2.6.22.19 --single-branch

the filesize recived is around 150mb, is this the correct way of doing it, what does this command likne mean ? v2.6.22.19 is a tag name right? why it can bed added after --branch ?

after cloning.

[oglop@localhost linux-stable]$ git status
# Not currently on any branch.
like image 547
Shuman Avatar asked Mar 13 '16 00:03

Shuman


People also ask

How do I clone and checkout a specific tag in Git?

1. git checkout Here, the idea is to clone a repository using the git-clonecommand and then check out the specific tag using git-checkout. # clone the remote repository $ git clone <repository> . # switch to the specific tag

How to clone a git repository?

While you can clone repositories with the git clone command, keep in mind that this clones the branch and the remote HEAD. This is usually master by default and includes all other branches in the repository.

How do I get all tags from a git repository?

When you clone a repository, all the tags associated with the repository will be pulled down. To fetch all the remote tags, use the fetch command as shown below. You can list down all the tags from the git repository using the following command. You can also search for tags with patterns.

How to clone using commit ID in Git?

There is no direct way to clone directly using the commit ID. But you can clone from a git tag. However, you can do the following workaround to perform a clone if it is really necessary.


1 Answers

providing v2.6.22.19 is the tag name and git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git is the repository url, try this:

git clone --depth 1 --single-branch --branch v2.6.22.19 git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git

the --depth 1 will download only the latest commit in the branch, this will also helps with the size issues

like image 200
Jiri Kremser Avatar answered Oct 16 '22 04:10

Jiri Kremser