Help us understand the problem. What is going on with this article?

gitで特定のタグのshallow repositoryを作る

More than 5 years have passed since last update.

最新のコミットだけcloneしてくるときにgit clone --depth=1としてshallow repositoryを作ったりしますが、最新ではなく特定のタグを取ってきたいときに。



$ git clone --depth=1 -b v1.2 git://

Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository’s HEAD, point to branch instead. In a non-bare repository, this is the branch that will be checked out. --branch can also take tags and detaches the HEAD at that commit in the resulting repository.



  • git clone 全部fetchしてmasterをチェックアウト
  • git clone -b refspec 全部fetchして特定ブランチ・タグをチェックアウト
  • git clone [-b refspec] --single-branch 指定したブランチ・タグのみfetchして(略)
  • git clone [-b refspec] --depth=n 指定したブランチ・タグの最新nコミットのみ(略)


$ git init
$ git fetch --depth=1 git:// v1.2
$ git checkout FETCH_HEAD


error: Trying to write non-commit object 99700ffadab431edc6cf0c9d6a78d4a9ea5c18d6 to branch refs/heads/master
fatal: Cannot update the ref 'HEAD'.




Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away