2

I need to checkout single folder of a tag from Bitbucket Git repo. I have checked out the single folder of a branch from the Bitbucket by using the following steps:

mkdir <repo>
cd <repo>
git init
git remote add -f origin <url>
git config core.sparseCheckout true
echo "some/dir/" >> .git/info/sparse-checkout
echo "another/sub/tree" >> .git/info/sparse-checkout
git pull origin master

Like this can we checkout the single folder of a tag?

Makoto
  • 104,088
  • 27
  • 192
  • 230

1 Answers1

4

First, shallow clone the repo, detach the HEAD at the tag, but do not check out anything:

git clone --depth 1 --branch <tag> --no-checkout <url/repo.git>
cd repo

Next, checkout the folder:

git checkout HEAD -- <path>

The option --branch might be misleading here, but it works also with tags. From the git-clone(1) Manual Page:

--branch can also take tags and detaches the HEAD at that commit in the resulting repository.

sergej
  • 17,147
  • 6
  • 52
  • 89
  • For example this is tag "clipper-release-18.1" we have 4 folders under tag i.e : bnw , bnw-clipper-db , bnw-clipper-jboss , bnw-clipper-workflows. So now i need to checkout one folder ( bnw-clipper-db)from bitbucket.Can anyone please help me out. – sai lakshmi Addala Jul 20 '18 at 07:02
  • 1
    @sailakshmiAddala It is unclear what you are asking. Are the folders in the same repo? Have you cloned the repo already? – sergej Jul 20 '18 at 07:44
  • yes, folders are in the same repo. No i have not cloned the repo. – sai lakshmi Addala Jul 20 '18 at 12:53