Skip to content

Instantly share code, notes, and snippets.

@ozgurgulsuna
Created January 21, 2025 15:08
Show Gist options
  • Save ozgurgulsuna/b3daf60211060a7ce7aad34990528303 to your computer and use it in GitHub Desktop.
Save ozgurgulsuna/b3daf60211060a7ce7aad34990528303 to your computer and use it in GitHub Desktop.

Gh is a command-line tool that brings GitHub to your terminal. It runs on Linux, macOS, and Windows. With gh, you can do everyday GitHub tasks like managing repositories, pull requests, issues, and more without leaving the command line.

Work seamlessly with GitHub from the command line.

USAGE
  gh <command> <subcommand> [flags]

CORE COMMANDS
  auth:        Authenticate gh and git with GitHub
  browse:      Open the repository in the browser
  codespace:   Connect to and manage codespaces
  gist:        Manage gists
  issue:       Manage issues
  org:         Manage organizations
  pr:          Manage pull requests
  project:     Work with GitHub Projects.
  release:     Manage releases
  repo:        Manage repositories

First, get the auth command to authenticate with GitHub. This command will open a browser window to authenticate with GitHub. After you authenticate, you can close the browser window and return to the terminal.

C:\Users\ozgur>gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations on this host? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Login with a web browser

! First copy your one-time code: xxxx-xxxx
Press Enter to open github.com in your browser...
✓ Authentication complete.
- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as ozgurgulsuna

Next, we list the repositories in the organization. We can use the org list command to list the repositories in the organization. The command will list the repositories in the organization with their names, descriptions, and URLs.

C:\Users\ozgur>gh repo list odtu

After listing the repositories, we can delete the repositories in bulk. For this we need to use a script. The script will delete the repositories in the organization in bulk. The script will delete the repositories in the organization with their names, descriptions, and URLs.

For Unix-based systems, you can use the following script to delete repositories in bulk. The script reads the repository names from a file and deletes them using the gh command.

#!/bin/bash

# Read the file containing repository names
while IFS= read -r repo; do
  # Delete the repository using the gh command
  gh repo delete "$repo" --yes
done < repos.txt

Run the Script: Save the script in a .sh file, for example, delete_repos.sh. Make sure to give it execute permission and then run it:

chmod +x delete_repos.sh
./delete_repos.sh

For Windows, you can use the following script to delete repositories in bulk. The script reads the repository names from a file and deletes them using the gh command.

# Read the file containing repository names
Get-Content repos.txt | ForEach-Object {
  # Delete the repository using the gh command
  gh repo delete $_ --yes
}

Run the Script: Save the script in a .ps1 file, for example, delete_repos.ps1. Make sure to run it in a PowerShell environment:

.\delete_repos.ps1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment