Skip to content
A bash script for bulk privatization of GitHub repositories
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md Clarify to enter computer password for one-line curl installation May 15, 2019
git-privatize Remove decrement May 15, 2019

README.md

git-privatize

A bash script for bulk privatization of GitHub repositories

Why does this exist?

GitHub doesn't allow you to make multiple repositories private at one time through their website. Their web app forces you to navigate to each repository's settings page and type in the repository name to make it private.

Alt Text

How does it work?

The script is very simple. The script...

  1. Assumes all the repositories you want to make private are in 1 root folder.
  2. cds into each folder.
  3. Deletes the remote repository on GitHub. Your local repository will remain intact.
  4. Creates a new remote repository on GitHub using the same name as the local repository. The new repository is automatically set to private.
  5. Sets the local repository's remote URL to the new repository's remote URL.
  6. Pushes the local repository's contents to GitHub.
  7. cds back to the root folder.
  8. Repeats steps 2-7 for all remaining repositories in the root folder.

Getting Started

Follow these instructions:

1. Install Hub

You need Hub to run special git commands from the command line.

If you have homebrew, you can install by running this command:

$ brew install hub
$ hub version
git version 1.7.6
hub version 2.2.3

Otherwise, please follow Hub's Official Installation Instructions

2. Enable the 'delete_repo' scope

  1. Navigate to github.com/settings/tokens
  2. Find the token for hub
  3. Check the box for "delete_repo"
  4. Confirm the change by clicking the "Update token" button at the bottom

3. Set up SSH agent

If GitHub currently asks you to enter your username and password everytime you push or pull, you're not using SSH agent.

As this tutorial states:

If you don't want to reenter your passphrase every time you use your SSH key, you can add your key to the SSH agent, which manages your SSH keys and remembers your passphrase.

Since we're going to be doing git commands in bulk, I highly recommend you set this up, or else Git may ask you for your credentials repeatedly.

Please follow the directions to set up SSH agent carefully.

4. Check that SSH agent is working

Try push/pulling and see if GitHub asks you for your credentials.

5. Move the repositories you want to make private into a single root folder

The folder name does not matter.

6. Install git-privatize

One-line installation with curl ⬇️. Enter your computer password if prompted.

curl -L -O https://raw.githubusercontent.com/ethannam/git-privatize/master/git-privatize && sudo mv git-privatize /usr/local/bin/ && sudo chmod +x /usr/local/bin/git-privatize

If you prefer to clone down this repo, make sure you move the git-privatize executable to your /usr/local/bin/ folder and set its +x permission. You can do that by running this line:

sudo mv git-privatize /usr/local/bin/ && sudo chmod +x /usr/local/bin/git-privatize

Usage Example

cd into the root folder that contains the repositories you want to make private.

For example:

$ pwd
/Users/ethannam/workspace
$ cd root-folder
$ pwd
/Users/ethannam/workspace/root-folder

From this root folder, if you run the ls command, you should see a list of the repos to make private.

$ ls -1d */
repo-name-1/
repo-name-2/
repo-name-3/
repo-name-4/
repo-name-5/

From this root folder, run the command below. You do not have to cd into each repo individually. The command below takes care of that for you.

git privatize

Enjoy!

Alt Text

You can’t perform that action at this time.