๐Ÿ› ๏ธ How I Made My Old Public GitHub Repos Private (All at Once)

Aman RajAman Raj
2 min read

So recently, I was cleaning up my GitHub profile โ€” and I realised I had so many random public repos ๐Ÿ˜…
Some were test projects, some half-done college stuff, and a few experiments I never even finished.

I didnโ€™t want people to see all that junk, but GitHub doesnโ€™t let us make multiple repos private at once using the normal UI.
So I found a simple solution using GitHub CLI. Hereโ€™s what I did ๐Ÿ‘‡


โœ… Step 1: Install GitHub CLI

I installed GitHub CLI using this command in CMD:

winget install GitHub.cli

If youโ€™re using Linux or Mac, you can check the install guide here: https://cli.github.com/manual/installation


โœ… Step 2: Login to GitHub from CLI

After installation, I logged in using:

gh auth login

It asked some questions:

  • I selected GitHub.com

  • Then chose HTTPS

  • Then opened browser and signed in โ€” done.


โœ… Step 3: Make a List of Repos

Now I made a list of repos I wanted to make private.

Just the repo names โ€” not the full URL.

For example:

repos=(
  test-app
  mini-project
  random-api
)

โœ… Step 4: Create Script to Make Repos Private

I created a file called make-private.sh and added this code:

#!/bin/bash

repos=(
  repo1
  repo2
  repo3
)

username="your_github_username"

for repo in "${repos[@]}"
do
  echo "Making $repo private..."
  gh repo edit "$username/$repo" --visibility private --accept-visibility-change-consequences
done

Replace:

  • repo1, repo2, etc. with your actual repo names

  • your_github_username with your real GitHub username


โœ… Step 5: Run the Script in Git Bash

Since Iโ€™m on Windows, I opened Git Bash (comes with Git) and ran:

chmod +x make-private.sh
./make-private.sh

Thatโ€™s it! All my selected repos became private. ๐Ÿซก


๐Ÿ‘จโ€๐Ÿ’ป Bonus Tip: See All Your Public Repos

If you want to list your current public repos, you can run:

gh repo list yourusername --visibility public

Copy the names from here and paste them into your script.


๐Ÿ’ญ Final Thoughts

This small trick helped me clean up my profile fast. Now only my good projects are public โ€” the rest are hidden from the world ๐Ÿ˜Ž

If you're a developer or student like me who has experimented a lot on GitHub, give this method a try. Simple and effective.

Let me know if it worked for you too!


If you found this blog helpful, share it with your dev friends or star my projects on GitHub ๐Ÿ’–

Thanks for reading! ๐Ÿ™Œ

20
Subscribe to my newsletter

Read articles from Aman Raj directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aman Raj
Aman Raj

Iโ€™m a full-stack developer and open-source contributor pursuing B.Tech in CSE at SKIT, Jaipur. I specialize in building scalable web apps and AI-driven tools. With internship experience and a strong portfolio, Iโ€™m actively open to freelance projects and remote job opportunities. Letโ€™s build something impactful!