marchello
Posts: 80
Joined: Fri Oct 11, 2013 8:59 am

partially clone bitbucket/git repository

Fri Dec 07, 2018 1:22 pm

Hi all,
Yes, I'm working under raspbian, but this is rather not OS or hardware-specific, that's why I'm asking it here in "offtopic".
I migrated from svn to bitbucket/git repository recently and would like to clone repository just partially.
It's easy in svn, but does not work in bitbucket/git for me.

So, to do it in svn, I just use /rootfolder/subfolder1/subfolder2 path.
Now, how do I perform the same in bitbucket/git if my url is https://bitbucket.example.com/project1/repository.git ?
Tried something like https://bitbucket.example.com/project1/ ... subfolder2 but it does not work.
Please advise.

Heater
Posts: 12078
Joined: Tue Jul 17, 2012 3:02 pm

Re: partially clone bitbucket/git repository

Sat Dec 08, 2018 1:57 pm

You can do it using a git feature know as "sparse checkout".

I have just tried this on a real repository at https://github.com/mtrebi/memory-allocators.git. Works a treat:

Code: Select all

$ git init
$ git remote add -f origin https://github.com/mtrebi/memory-allocators.git
$ ls
$ git config core.sparseCheckout true
$ echo "src/" >> .git/info/sparse-checkout
$ git pull origin master
$ ls
src
$ ls src/
Allocator.cpp  Benchmark.cpp  CAllocator.cpp  FreeListAllocator.cpp  LinearAllocator.cpp  main.cpp  PoolAllocator.cpp  StackAllocator.cpp
 
You may also want to add use of the "shallow clone" feature to limit the amount of history fetched.

Have a look here https://stackoverflow.com/questions/600 ... repository for a discussion and perhaps other techniques you could use.

marchello
Posts: 80
Joined: Fri Oct 11, 2013 8:59 am

Re: partially clone bitbucket/git repository

Sun Dec 09, 2018 4:22 pm

Heater,
I was able to reproduce your steps (I used another repository though), so it is great, thank you.
Just wanted to let know that it seems it takes the same time to fetch everything comparing to small part. Or is it just my environment...
Anyway,

Code: Select all

git remote add -f origin https://user:password@git.example.com/folder1/repository1.git
took most of time. Maybe, just maybe (I did not test it yet), this step

Code: Select all

git pull origin master
would take longer on path with bigger amount of files.

Heater
Posts: 12078
Joined: Tue Jul 17, 2012 3:02 pm

Re: partially clone bitbucket/git repository

Sun Dec 09, 2018 5:05 pm

Great it works.

Hmm... You are right. I was just playing with this on a small repo so it's hard to make timing comparisons. between the different techniques.

Did you have a read of that link I posted, there are other ideas in there that might help if things are really big and slow.

For example:

$ git clone --no-checkout --depth 1 --single-branch https://github.com/mtrebi/memory-allocators.git

"depth 1" limits the amount of history that is downloaded to just the latest commit.

"--single branch" limits things to the main branch of the repo.

Then you can do that selective checkout thing to get only the sources you want out.

What repo are you cloning?

Git repo size has never been a concern for me. Even when they are big it's not something one does very often. Subsequent pulls are much quicker.

marchello
Posts: 80
Joined: Fri Oct 11, 2013 8:59 am

Re: partially clone bitbucket/git repository

Mon Dec 10, 2018 8:04 pm

Well, that's our company's internal repository.
I believe limiting to branch and/or to latest commits should work for someone. It's a pity, but it's not my way. Thanks anyway!

I was asking because sometimes it's boring to wait while cloning repository, it is quite big. Though it is good moment to prepare a cup of tea)

Return to “Off topic discussion”