Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for GitHub Clones Replenish
Jolene Langlinais
Jolene Langlinais

Posted on • Edited on

     

GitHub Clones Replenish

This configuration helps make my consistent pulling of repositories from GitHub a bit easier. Especially so if repositories can frequently change names, or the list of all current repositories can change.

I wrote a script to clone all (specific) repositories in an organization.

Context

My setup is currently running macOS Catalina, using iTerm2 with Bash.

You will needhomebrew,jq, andgh:

/bin/bash-c"$(curl-fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"brewinstalljqbrewinstallgh
Enter fullscreen modeExit fullscreen mode

Operation

For this configuration, ensure you're in the desired directory and this script exists in the directory. This will create a new directory (named the date, i.e.2020-12-06T21:16:47Z) where you are, and then dump all the clones within that directory:

bash ./<SCRIPT_NAME>.sh INSERT_GITHUB_ORGANIZATION# bash ./replenishRepos.sh accordproject
Enter fullscreen modeExit fullscreen mode

Configuration

All

My configuration within thisscriptName.sh file in order to cloneall repositories within an organization:

#!/bin/bashCURRENTDATE=$(date-u +"%Y-%m-%dT%H%M%SZ")repositories=(`gh api /orgs/$1/repos--paginate | jq-r'.[]' |tr'\n''  '`)mkdir"${CURRENTDATE}"cd"${CURRENTDATE}"echo"####"echo"## Cloning repositories"echo"####"forrepoin"${repositories[@]}"doecho"####"echo"# Cloning repo https://github.com/clauseHQ/${repo}.git"echo"####"  git clone"https://github.com/clauseHQ/${repo}.git"done
Enter fullscreen modeExit fullscreen mode

Specific

My configuration within thisscriptName.sh file in order to cloneonly repositories within an organization that have specific prefixes, are archived, and are private:

#!/bin/bashCURRENTDATE=$(date-u +"%Y-%m-%dT%H%M%SZ")repositories=(`gh api /orgs/$1/repos--paginate | jq-r'.[] | select(.private == <BOOLEAN> and .archived == <BOOLEAN>) | .name | select(test("<PREFIX_1>") or test("<PREFIX_2>"))' |tr'\n''  '`)mkdir"${CURRENTDATE}"cd"${CURRENTDATE}"echo"####"echo"## Cloning repositories into${CURRENTDATE}"echo"####"forrepoin"${repositories[@]}"doecho"####"echo"# Cloning repo https://github.com/clauseHQ/${repo}.git"echo"####"  git clone"https://github.com/clauseHQ/${repo}.git"done
Enter fullscreen modeExit fullscreen mode

In this configuration, I can select archived or private repositories, and/or repositories with a specific prefix in the name.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Software + Project Mgmt :: Speaker + Writer :: Chef :: Comedy + Climb
  • Location
    New York, NY
  • Work
    Full Stack Software Engineer
  • Joined

More fromJolene Langlinais

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp