Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Fork Batch Tools

Batch management tools for GitHub fork repositories — sync or delete forks in one go.

Scripts

Script Description
sync-forks.sh Batch sync all fork repositories in a GitHub organization with their upstream parents
delete-forks.sh Batch delete all forked repositories under a GitHub user account
clone-forks.sh Discover upstream repos via ariacompute forks, then fork them into craftsland

Prerequisites

1. Install GitHub CLI

Ubuntu/Debian:

sudo apt install gh

macOS:

brew install gh

Or download from GitHub CLI official website

2. Authenticate GitHub CLI

gh auth login

3. Set GitHub Token

export GITHUB_TOKEN="your_github_pat_token"

Recommended to add the token to environment variables or config files to avoid setting it manually each time.


sync-forks.sh

Batch sync all fork repositories for GitHub user craftsland with their upstream parents.

Usage

# Basic usage — sync all forks
./sync-forks.sh

# Dry Run mode — preview without making changes
./sync-forks.sh --dry-run

# Force sync — execute even if already up to date
./sync-forks.sh --force

# Show help
./sync-forks.sh --help

Parameters

Parameter Description
--dry-run Preview mode, shows what would be synced without making changes
--force Force sync, execute even if fork is already in sync with upstream
--help Show help information

How It Works

  1. Fetch all fork repositories for user craftsland via GitHub API
  2. For each fork, resolve its upstream (parent) repository
  3. Use gh repo sync to pull updates from upstream into the fork
  4. Log success / failure per fork and print a summary

Example Output

=========================================
GitHub Fork Batch Sync for craftsland
=========================================

Syncing fork: craftsland/project-a
  From parent: original-org/project-a
  ✓ Successfully synced craftsland/project-a

Syncing fork: craftsland/project-b
  From parent: original-org/project-b
  ✓ Successfully synced craftsland/project-b

=========================================
Sync Summary
=========================================
Total forks processed: 2
Successful: 2
Failed: 0

clone-forks.sh

Discover upstream repositories from all forks in the ariacompute GitHub organization, then fork the same upstream repos into the craftsland user account.

Usage

# Basic usage — fork all discovered upstream repos
./clone-forks.sh

# Dry Run mode — preview without making changes
./clone-forks.sh --dry-run

# Force mode — fork even if craftsland already has a fork
./clone-forks.sh --force

# Show help
./clone-forks.sh --help

Parameters

Parameter Description
--dry-run Preview mode, shows which upstream repos would be forked without making changes
--force Force fork even if craftsland already has a fork of the same upstream
--help Show help information

How It Works

  1. Fetch all fork repositories in the ariacompute organization via GitHub API
  2. For each fork, resolve its upstream (parent) repository
  3. Deduplicate — if the same upstream was forked multiple times, fork it only once
  4. Skip upstreams that craftsland has already forked (unless --force)
  5. Use gh repo fork to fork each upstream into the craftsland account
  6. Log success / failure per upstream and print a summary

Example Output

=========================================
GitHub Fork Cloner
=========================================
Source org (to discover upstreams): ariacompute
Target user (to fork into):         craftsland

Fetching fork list from organization: ariacompute...

  Found upstream: upstream-org/project-a  (via fork ariacompute/project-a)
  Found upstream: upstream-org/project-b  (via fork ariacompute/project-b)
  Skipping already-forked: upstream-org/project-c  (craftsland already has a fork)

Found 2 upstream repo(s) to fork:
  - upstream-org/project-a
  - upstream-org/project-b

Forking upstream: upstream-org/project-a
  Into account: craftsland
  ✓ Successfully forked upstream-org/project-a

Forking upstream: upstream-org/project-b
  Into account: craftsland
  ✓ Successfully forked upstream-org/project-b

=========================================
Fork Summary
=========================================
Total upstream repos processed: 2
Successful: 2
Failed: 0

delete-forks.sh

Batch delete all forked repositories under GitHub user craftsland.

Usage

# Interactive mode — list forks, confirm, then delete one by one
./delete-forks.sh

# Dry Run mode — preview without deleting
./delete-forks.sh --dry-run

# Force mode — skip confirmation and delete all forks directly
./delete-forks.sh --force

# Show help
./delete-forks.sh --help

Parameters

Parameter Description
--dry-run Preview mode, shows which forks would be deleted without deleting them
--force Skip confirmation prompt and delete all forks immediately
--help Show help information

How It Works

  1. Fetch all repositories under user craftsland, filtering to only forks
  2. Display the full list and ask for confirmation (unless --force)
  3. Delete each fork via DELETE /repos/{full_name} API
  4. Print per-repo status and a final summary

Example Output

=========================================
GitHub Fork Batch Delete for craftsland
=========================================

Fetching fork list...

Found 5 fork(s):
  - craftsland/forked-repo-1
  - craftsland/forked-repo-2
  - craftsland/forked-repo-3
  - craftsland/forked-repo-4
  - craftsland/forked-repo-5

Are you sure you want to delete ALL 5 fork(s)? [y/N] y

Deleting fork: craftsland/forked-repo-1
  ✓ Successfully deleted craftsland/forked-repo-1

...

=========================================
Delete Summary
=========================================
Total forks processed: 5
Deleted: 5
Failed: 0

Important Notes

  • sync-forks: Token needs repo scope to sync.
  • clone-forks: Token needs repo scope to fork repos. The authenticated gh user must have permission to fork the upstream repos.
  • delete-forks: Token needs delete_repo scope. Deletion is irreversible — always run --dry-run first to verify.
  • All scripts use gh api / gh repo under the hood and are compatible with GITHUB_TOKEN.

Troubleshooting

Common Issues

1. Token not set

Error: GITHUB_TOKEN environment variable is not set

Solution: Export GITHUB_TOKEN in your shell.

2. Not authenticated with GitHub CLI

Error: HTTP 401: Unauthorized

Solution: Run gh auth login to re-authenticate.

3. Insufficient permissions

Error: Resource not accessible by integration

Solution: Verify the token has the required scopes (repo for sync, delete_repo for delete).

License

MIT License

About

Batch management tools for GitHub fork repositories

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages