Skip to content

Instantly share code, notes, and snippets.

@anilktechie
Forked from davegallant/gh-clone-org
Created January 20, 2022 00:34
Show Gist options
  • Select an option

  • Save anilktechie/f27cfe2326ed1e9ba631fab4f17d2bcc to your computer and use it in GitHub Desktop.

Select an option

Save anilktechie/f27cfe2326ed1e9ba631fab4f17d2bcc to your computer and use it in GitHub Desktop.

Revisions

  1. @davegallant davegallant revised this gist Jun 23, 2021. 1 changed file with 7 additions and 4 deletions.
    11 changes: 7 additions & 4 deletions gh-clone-org
    Original file line number Diff line number Diff line change
    @@ -21,10 +21,13 @@ repos_complete=0
    echo

    echo "$repos" | while read -r repo; do
    repo_name="$(echo "$repo" | cut -f1)"
    echo -ne "\r\e[0K[ $repos_complete / $repo_total ] Cloning $repo_name"
    gh repo clone "$repo_name" "$repo_name" -- -q 2> /dev/null || (cd "$repo_name"; git pull -q)
    repos_complete=$((repos_complete + 1))
    repo_name="$(echo "$repo" | cut -f1)"
    echo -ne "\r\e[0K[ $repos_complete / $repo_total ] Cloning $repo_name"
    gh repo clone "$repo_name" "$repo_name" -- -q 2>/dev/null || (
    cd "$repo_name"
    git pull -q
    )
    repos_complete=$((repos_complete + 1))
    done

    echo "Finished cloning all repos in $org."
  2. @davegallant davegallant revised this gist Jun 23, 2021. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions gh-clone-org
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@

    # This script clones all repos in a GitHub org
    # It requires the GH CLI: https://cli.github.com
    # It can be re-run to collect new repos and pull the latest changes

    set -euo pipefail

    @@ -10,7 +11,7 @@ USAGE="Usage: gh-clone-org <user|org>"
    [[ $# -eq 0 ]] && echo >&2 "missing arguments: ${USAGE}" && exit 1

    org=$1
    limit=1000
    limit=9999

    repos="$(gh repo list "$org" -L $limit)"

    @@ -22,8 +23,8 @@ echo
    echo "$repos" | while read -r repo; do
    repo_name="$(echo "$repo" | cut -f1)"
    echo -ne "\r\e[0K[ $repos_complete / $repo_total ] Cloning $repo_name"
    gh repo clone "$repo_name" "$repo_name" -- -q
    gh repo clone "$repo_name" "$repo_name" -- -q 2> /dev/null || (cd "$repo_name"; git pull -q)
    repos_complete=$((repos_complete + 1))
    done

    echo "Cloning Complete"
    echo "Finished cloning all repos in $org."
  3. @davegallant davegallant renamed this gist May 9, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @davegallant davegallant revised this gist May 9, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gh-clone-org.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/usr/bin/env bash

    # This script clones all repos in a GH org
    # This script clones all repos in a GitHub org
    # It requires the GH CLI: https://cli.github.com

    set -euo pipefail
  5. @davegallant davegallant revised this gist May 9, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gh-clone-org.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    #!/usr/bin/env bash

    # This script clones all repos in a GH org
    # It requires the GH CLI: https://cli.github.com

    set -euo pipefail

  6. @davegallant davegallant created this gist May 9, 2021.
    28 changes: 28 additions & 0 deletions gh-clone-org.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/usr/bin/env bash

    # This script clones all repos in a GH org

    set -euo pipefail

    USAGE="Usage: gh-clone-org <user|org>"

    [[ $# -eq 0 ]] && echo >&2 "missing arguments: ${USAGE}" && exit 1

    org=$1
    limit=1000

    repos="$(gh repo list "$org" -L $limit)"

    repo_total="$(echo "$repos" | wc -l)"
    repos_complete=0

    echo

    echo "$repos" | while read -r repo; do
    repo_name="$(echo "$repo" | cut -f1)"
    echo -ne "\r\e[0K[ $repos_complete / $repo_total ] Cloning $repo_name"
    gh repo clone "$repo_name" "$repo_name" -- -q
    repos_complete=$((repos_complete + 1))
    done

    echo "Cloning Complete"