Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pa-0/7489d850fa5e620db4a47b3aab8b57c3 to your computer and use it in GitHub Desktop.
Save pa-0/7489d850fa5e620db4a47b3aab8b57c3 to your computer and use it in GitHub Desktop.

Revisions

  1. @itsazzad itsazzad renamed this gist Aug 25, 2021. 1 changed file with 0 additions and 0 deletions.
  2. @itsazzad itsazzad renamed this gist Aug 23, 2021. 1 changed file with 0 additions and 0 deletions.
  3. @itsazzad itsazzad renamed this gist Aug 23, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gh-clone-org-upstream → gh-org-clone-create-add-push
    Original file line number Diff line number Diff line change
    @@ -27,6 +27,7 @@ echo "$repos" | while read -r repo; do
    gh repo clone "$repo_name" "$repo_name" -- -q 2>/dev/null || (
    cd "$repo_name"
    git pull -q
    gh repo create $upstream/$f --public --confirm
    git remote add upstream [email protected]:$upstream/$repo_name.git
    git push upstream
    )
  4. @itsazzad itsazzad renamed this gist Aug 23, 2021. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions gh-clone-org → gh-clone-org-upstream
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,17 @@
    #!/usr/bin/env bash

    # This script clones all repos in a GitHub org
    # This script clones all repos in a GitHub org and pushes to the upstream
    # 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

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

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

    org=$1
    upstream=$2
    limit=9999

    repos="$(gh repo list "$org" -L $limit)"
    @@ -26,8 +27,8 @@ echo "$repos" | while read -r repo; do
    gh repo clone "$repo_name" "$repo_name" -- -q 2>/dev/null || (
    cd "$repo_name"
    git pull -q
    git remote add upstream [email protected]:$upstream/$repo_name.git
    git push upstream
    )
    repos_complete=$((repos_complete + 1))
    done

    echo "Finished cloning all repos in $org."
  5. @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."
  6. @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."
  7. @davegallant davegallant renamed this gist May 9, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. @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
  9. @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

  10. @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"