Cloning a repo without tags?

I want to create a bare git project without tags using clone. But through Google I found out that there is no such parameter as " --no-tags ".

Is there a way to clone without tags as below?

 $ git clone {path}/test.git --no-tags --mirror 

Any help would be appreciated! :)

+6
source share
4 answers

I also got it through some trails and googling.

I used the steps below to do this.

1) Initialize a bare repo:

 mkdir project cd project git init --bare 

2) Add your remote and configure the appropriate refspec for it:

 git remote add origin <REPO_URL> git config remote.origin.fetch +refs/heads/*:refs/heads/* git config remote.origin.tagopt --no-tags 

3) Get data:

 git remote update origin 

If you want the tags to be omitted only on the first fetch, omit by setting the variable remote..tagopt and using

 git fetch --no-tags 

to receive data. Note that the next selection without "--no-tags" will retrieve tags that can be retrieved automatically if you do not install remote..tagopt before.

+5
source

With Git 2.13.x / 2.14 (Q2 2017) this will be possible (i.e. a clone without tags)

See commit 1524ccd , commit 0dab246 , commit 28d67d9 (April 26, 2017) Γ†var ArnfjΓΆrΓ° Bjarmason ( avar ) .
(merger of Junio ​​C Hamano - gitster - to commit a1fdc85 , May 16, 2017

clone : add --no-tags option to clone without tags

Add the --no-tags option to clone without retrieving any tags.

Without this change, there is no easy way to clone a repository without also retrieving its tags.

When --single-branch supplied, the main remote branch will be cloned, but tags will also be executed and retrieved.
Now --no-tags you can add --single-branch to clone a repository without a tag and which only tracks one branch upstream.

This option works without --single-branch , and will make a normal clone but not retrieve tags.

Many Git teams pay some fixed overhead depending on the number of links. For instance. creating ~ 40k tags in linux.git will cause the command, for example, git log -1 >/dev/null , to work in a second, and not in milliseconds, in addition, many other things will slow down, for example. " git log <TAB> " with the completion of bash will slowly show ~ 40k links instead of 1.

The user may want to avoid all this overhead by simply using a repository like this to view the master branch, or something like a CI tool, might want to keep this branch up to date without worrying about any other links .

Without this change, the only way to achieve this was to either manually configure the configuration in the new repository:

 git init git && cat >git/.git/config <<EOF && [remote "origin"] url = git@github.com :git/git.git tagOpt = --no-tags fetch = +refs/heads/master:refs/remotes/origin/master [branch "master"] remote = origin merge = refs/heads/master EOF cd git && git pull 

This requires hard coding of the name " master ", which cannot be the main --single-branch , or, alternatively, by setting tagOpt=--no-tags immediately after cloning and removing any existing tags:

 git clone --single-branch git@github.com :git/git.git && cd git && git config remote.origin.tagOpt --no-tags && git tag -l | xargs git tag -d 

Which, of course, was also subtly buggy if --branch was pointed to a tag, leaving the user in a separate head:

 git clone --single-branch --branch v2.12.0 git@github.com :git/git.git && cd git && git config remote.origin.tagOpt --no-tags && git tag -l | xargs git tag -d 

Now all this complexity becomes much easier:

 git clone --single-branch --no-tags git@github.com :git/git.git 

Or in the case of cloning a single tag "branch":

 git clone --single-branch --branch v2.12.0 --no-tags git@github.com :git/git.git 
+3
source

"Mirror" means "tags": you cannot have the first without it.

Essentially, --mirror means:

  • naked clone with
  • ref-spec to read reading refs/*:refs/*

Since tags live in refs/tags/ , the second marker above means that the tags are copied.

To avoid copying tags, you will need a different set of refspec. Select the one (s) you want to copy (possibly refs/heads/* and refs/notes/* ) and list them explicitly in your bare clone. (You can start by creating a complete --mirror clone, then edit the configuration file and delete any unnecessary links already copied.)

You might also want to set remote.name.tagopt to --no-tags to disable automatic tag matching fetching.

0
source

According to git / 2.14.0 Release Notes, there will now be support for excluding tags when cloning a repository.

 "git clone" learned the "--no-tags" option not to fetch all tags initially, and also set up the tagopt not to follow any tags in subsequent fetches. 

In the future, use the following command: -

 git clone <repositoryUrl> --no-tags 
0
source

Source: https://habr.com/ru/post/972718/


All Articles