How to Clone and Pull All GitHub Organization Repositories at Once

If you work in a company or development team, you may have access to a GitHub Organization containing many repositories. For example, your organization might have:

  • ERP Backend

  • ERP Frontend

  • HR Management

  • Inventory

  • Production

  • Reporting

  • Mobile App

  • APIs

  • Several other internal projects

Cloning each repository manually can become annoying and time-consuming. Fortunately, GitHub CLI makes this much easier. In this article, I'll show you how to clone all repositories from a GitHub Organization into a single folder and later update them all using a single PowerShell command.

We will use:

  • Git

  • GitHub CLI (gh)

  • PowerShell

  • A GitHub account with access to the organization repositories

GitHub CLI provides the gh repo list command for listing repositories owned by a user or organization, and it supports JSON output and filtering with --jq.

For this example, we'll use a generic organization name:

ORG_NAME

Step 1: Install GitHub CLI

First, install GitHub CLI on your computer.

You can get it from the official GitHub CLI website:

GitHub CLI

After installation, open PowerShell and check:

gh --version

You should see the installed GitHub CLI version.


Step 2: Login to GitHub

Run:

gh auth login

Follow the instructions and authenticate with the GitHub account that has access to the ORG-NAME organization.

You can verify your authentication with:

gh auth status

Step 3: Create a Folder for the Repositories

For example:

mkdir D:\GitHub\ORG_NAME

Then move into the folder:

cd D:\GitHub\ORG_NAME

Step 4: Clone All Repositories

Now comes the useful part.

Run:

gh repo list ORG_NAME --limit 1000 --json nameWithOwner --jq '.[].nameWithOwner' | ForEach-Object { gh repo clone $_ }

That's it.

GitHub CLI will retrieve the repositories belonging to the organization and clone them into the current folder.

The --limit 1000 option allows the command to retrieve up to 1,000 repositories instead of the default limit.

Your folder will look something like:

D:\GitHub\ORG_NAME
│
├── ERP-Backend
├── ERP-Frontend
├── HRMS
├── Inventory
├── Production
├── Reporting
└── ...

Step 5: Update All Repositories With One Command

After the repositories have been cloned, you don't want to clone them again every day.

Instead, you want to:

  • Pull existing repositories

  • Clone newly created repositories

  • Do everything with one command

Go to your organization folder:

cd D:\GitHub\ORG-NAME

Then run:

gh repo list ORG_NAME --limit 1000 --json nameWithOwner --jq '.[].nameWithOwner' | ForEach-Object { $repo=$_.Split("/")[1]; if (Test-Path $repo) { git -C $repo pull } else { gh repo clone $_ } }

This command automatically checks every repository.

If the repository already exists:

git pull

is executed.

If it doesn't exist:

gh repo clone

is executed.

So you don't have to manually visit every repository.


A More User-Friendly Version

If you want to see what's happening while the command runs, use this version:

gh repo list ORG_NAME --limit 1000 --json nameWithOwner --jq '.[].nameWithOwner' | ForEach-Object { $repo=$_.Split("/")[1]; if (Test-Path $repo) { Write-Host "Pulling $repo..." -ForegroundColor Green; git -C $repo pull } else { Write-Host "Cloning $repo..." -ForegroundColor Cyan; gh repo clone $_ } }

You'll see something like:

Pulling ERP-Backend...
Already up to date.

Pulling ERP-Frontend...
Already up to date.

Cloning New-Project...
✓ Cloned repository

This is much more convenient when you have many repositories.


Why This Is Useful

Imagine your organization has 30 repositories.

Without automation, you might have to do:

cd Project1
git pull

cd ../Project2
git pull

cd ../Project3
git pull

...

That's repetitive.

With the command above, you simply run:

cd D:\GitHub\ORG_NAME

and then:

gh repo list ORG_NAME --limit 1000 --json nameWithOwner --jq '.[].nameWithOwner' | ForEach-Object { $repo=$_.Split("/")[1]; if (Test-Path $repo) { git -C $repo pull } else { gh repo clone $_ } }

One command can synchronize the whole organization.


Important: Be Careful With Local Changes

There is one important thing to remember.

Suppose you are working on:

Project-Backend

and you have modified some files locally but haven't committed them yet.

When the script runs:

git pull

Git may refuse to pull if your local changes conflict with incoming changes.

That's actually a good thing.

You should not use commands such as:

git reset --hard

in an automatic synchronization script unless you fully understand the consequences.

Otherwise, you could accidentally lose your local work.


Another Useful Option

You can also tell GitHub CLI to exclude archived repositories:

gh repo list ORG_NAME --limit 1000 --no-archived --json nameWithOwner --jq '.[].nameWithOwner'

GitHub CLI supports options such as --archived, --no-archived, --fork, --source, and visibility filters when listing repositories.

For example, if you only want non-archived repositories:

gh repo list ORG_NAME --limit 1000 --no-archived --json nameWithOwner --jq '.[].nameWithOwner'

My Recommended Setup

For a development team, I would keep all organization repositories under one directory:

D:\GitHub\ORG_NAME\

Then whenever you start your workday, simply run:

cd D:\GitHub\ORG_NAME

followed by the synchronization command.

This gives you a simple local mirror of the repositories you have access to.


Final Command

If you only want to remember one command, remember this:

gh repo list ORG_NAME --limit 1000 --json nameWithOwner --jq '.[].nameWithOwner' | ForEach-Object { $repo=$_.Split("/")[1]; if (Test-Path $repo) { git -C $repo pull } else { gh repo clone $_ } }

It will:

Existing repository → Pull latest changes

New repository → Clone it

All repositories → Process automatically

That's a much easier way to manage a GitHub organization with many repositories.


Conclusion

Managing dozens of GitHub repositories manually can become repetitive very quickly.

Using GitHub CLI and a small PowerShell command, you can automate most of that work.

Once configured, keeping your local copy of an organization's repositories up to date becomes a simple one-command task.

For developers working with large company repositories, this small automation can save a surprising amount of time.

0 Comments