Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Clone all repositories from a project in stash

Vishal Rekala September 5, 2013

Is there a way i can clone all the existing repositories from a project in stash in a simple way?

Lets say I have project called "A" and there are 5 reporitories say 1,2,3,4,5. I would like to clone all the repositories in project A in a simple way rather than doing

git clone http://mystash.com/A/1.git

git clone http://mystash.com/A/2.git

git clone http://mystash.com/A/3.git

git clone http://mystash.com/A/4.git

git clone http://mystash.com/A/4.git

thanks!!!

7 answers

1 accepted

4 votes
Answer accepted
cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 5, 2013

Hi Vishal,

I'm afraid Git doesn't allow that, they have to be cloned separately.

Hypothetically you could have another repository that uses Submodules to link to the others, and then use git submodule to clone them down. You would have to keep that other repository up-to-date, which would be a pain. Submodules link by using commits. I personally wouldn't recommend that - it's not really buying you much.

You could also write a script that uses Stash's REST resources to list the repositories in a project and then clone them all in succession.

I'm curious - how often are people clone the repositories? Once you have them locally you dont' really need to clone them again. Is this for a build perhaps?

Cheers,

Charles

Vishal Rekala September 5, 2013

Hey charles - Thanks for the prompt response. Yes it is for the build purpose. I will be working all the repositories of all the projects from various teams. I want a simply way to clone all repositories.

Like Gabriel_Degret likes this
cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 5, 2013

Hi Vishal,

I thought so. :)

So it's gets interesting at this point. What kind of dependencies do you have between each of your repositories then? If you clone them all down, how do you know what version/branch of each repository to build? Is it always master? If that's the case how do you handle old release versions?

Generally I would recommend that you would except one build per repository. So what we do here is use maven as our dependency management, and we use maven versions to tie two separate repositories together. It means we can make changes to one repository without affecting another.

You might find that submodules are an easy(ish) way to get started with this kind of versioning. As mentioned previously, you can have another repository would would then 'link' all of your child repositories together at specific versions. You would then need to modify this parent repository before changes in a child repo was built. This may or may not be what you are looking for. Depending on your language/environment you might be able to use something like Ruby Gems, Python Eggs, etc. I would recommend these over using submodules, but would require a more substantial change to your build process.

The quick answer to your actual question would proably be to just configure your build (Bamboo? Jenkins?) to clone each repository manually. I know in Bamboo you can have multiple repositories per plan. It's not really an automated solution - but it's probably the easiest (assuming you don't have like 100 repositories).

Sorry for the long rant.

Charles

Vishal Rekala September 5, 2013

Hey Charles -

There is no dependency between the repositories. I want latest version of code of all the repositories to be available. We will build anything which is latest and yes it is always master. I am handling old releases with TAG's.

I have around 20 repositories. And My build system(Jenkins) is configured to build individual repositories. Its just my individual request that I want to clone each and every repository in stash.

I will try submodules and thanks again!!!

-Vishal

7 votes
Faik Uygur January 20, 2015

Here is quick script using stashy - a python rest api client for stash: https://github.com/RisingOak/stashy

# stashget PROJECT_KEY

 

#!/usr/bin/python
import sys
import os
import stashy

stash = stashy.connect("http://localhost/stash", "USERNAME", "PASSWORD")
for repo in stash.projects[sys.argv[1]].repos.list():
    for url in repo["links"]["clone"]:
        if (url["name"] == "ssh"):
            os.system("git clone %s" % url["href"])
            break
Bob Henkel March 24, 2015

Thanks Faik, works awesome!

ShrutiM April 9, 2015

hi, as of 'm running the above script m getting error. so can you please tell me which all places i have to edit and place my data.

Yakup Ad July 13, 2019

You need create ssh key! 
Steps: Open Terminal

ssh-keygen 
pbcopy < ~/.ssh/id_rsa.pub (This command copied clipboard your ssh key)

 1)Go to your stash site. Click Manage Account TabScreen Shot 2019-07-14 at 02.13.36.png2) Click Add key ButtonScreen Shot 2019-07-14 at 02.14.11.png3)Paste (ctrl + v) Key Area -> Click Add key buttonScreen Shot 2019-07-14 at 02.14.18.png


4-> Run your python script

David Kinkade September 28, 2022

Thanks Faik this worked great!

3 votes
Divin Honnappa December 8, 2016

If you're using git bash or cmd in your local (which I think most of us use)
you can just type the following 

for i in reponame1 reponame2 reponame3 ...
do
git clone http://username@bitbucketaccount.com/scm/"projectcode"/$i.git
done

Natesh Sharan July 15, 2019

@Divin Honnappa thanks that was simple and effective

1 vote
Ian Boardman October 31, 2016

$ curl -s  -k --user YourUserName https://api.bitbucket.org/1.0/user/repositories | python -c 'import sys, json; r = json.loads(sys.stdin.read()); [sys.stdout.write(d["name"]+"\n") for d in r]'

 

Jincymol Chacko February 14, 2019

goood

0 votes
eacikoglu March 3, 2018

Using @archenroot answer ,I have created a repo with springBoot Rest api to clone all repos from url.

https://github.com/enesacikoglu/BitbucketRepoCloner

Thanks to archenroot

Regards.

0 votes
archenroot January 31, 2017

Hi guys, I found this discussion while looking for similar solution. The python stashy didn't work for me, so I wrote simple Java app which do the same:

https://gist.github.com/archenroot/1d11f58d182163ce55bdafcdfe11d411

It actually access all projects where user has permission to read, iterate trough all repositories of all projects and clone them to directory structure:

project1

|---- repo1

|---- repo2

project2

|---- repo1

|---- repo2

 

etc..

0 votes
Christopher Timm January 21, 2015

We are facing the same problems with > 50 projects and > 100 repositories. Most of them are built with Jenkins . 

There is one project to configure the build jobs of Jenkins and I am working on the small management component (internally called "Metagit"). This is based on the stash-java-client (https://bitbucket.org/atlassianlabs/stash-java-client/) and uses Ant as a frontend.

 

We automate the following workflows:

1. Pull / Clone a set of repos

2. Create a feature branch

2a. Search and modify (if needed) e.g. Maven versions ...

2b. Commit and Push

3. Create a Pull Request for the new branch

 

Cheers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events