Skip to content

Instantly share code, notes, and snippets.

@abenezerBelachew
Created April 21, 2023 20:34
Show Gist options
  • Save abenezerBelachew/1c8f4a0dcbfd66b14a7eb00d9f103a60 to your computer and use it in GitHub Desktop.
Save abenezerBelachew/1c8f4a0dcbfd66b14a7eb00d9f103a60 to your computer and use it in GitHub Desktop.
A simple python script to clone the repositories in an organization.
import os
import requests
# Set the GitHub organization and access token
org = "" # 'getsentry' for example
access_token = ""
# Set the base URL for the GitHub API
base_url = 'https://api.github.com/orgs/{}/repos'.format(org)
# Set the directory where the repositories will be cloned
clone_dir = "" # '/home/username/testrepos' for example
# Set the headers to include the access token
headers = {'Authorization': 'token {}'.format(access_token)}
# Make a GET request to the GitHub API to get the list of repositories
response = requests.get(base_url, headers=headers)
# Parse the response JSON to get the repository names
repos = [repo['name'] for repo in response.json()]
# Clone each repository to the local file system
for repo in repos:
repo_url = 'https://github.com/{}/{}'.format(org, repo)
clone_path = os.path.join(clone_dir, repo)
os.system('git clone {} {}'.format(repo_url, clone_path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment