Script to git clone all repositories of a user from bitbucket

Script to git clone all repositories of a user from bitbucket

There you go!

1) Ensure python3 is available.

prompt> python3 -V

prompt> Python 3.7.2

(Should work with python2 also, but not tested)

2) Make sure you have “requests” module imported

prompt>pip3 install requests

3) create a .netrc file in home directory.

prompt> cat ~/.netrc


login <your login name>

password <your password>

4) The file

#!/usr/bin/env python3

import sys
import requests
import os
import netrc
from os.path import expanduser
from urllib import parse as urlparse
home = expanduser("~")
path = home
netrc = netrc.netrc(home+"/.netrc")
user, account, password = netrc.authenticators("")
s = requests.Session()
s.auth = (user,password)
r = s.get("")
x = r.json()
userenc = urlparse.quote_plus(user)
curr = os.getcwd()

for repo in x:
    reponame = repo['name']
    print("Cloning "+reponame);
    reponameenc = urlparse.quote_plus(reponame)
    clone = "git clone"+userenc+"/"+reponameenc+".git"


5) Run the python script to clone all your repositories


READ  Explaining SOLR, SOLRCloud to the rookie by Exdiscoran


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Terms of Use | Privacy Policy 
2018-2019 © eXitDiscount
eXitDiscount may collect commission on any purchases made through above links, at no extra cost to you. eXitDiscount is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to