A bash script for bulk privatization of GitHub repositories
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.
The script is very simple. The script...
- Assumes all the repositories you want to make private are in 1 root folder.
cd
s into each folder.- Deletes the remote repository on GitHub. Your local repository will remain intact.
- Creates a new remote repository on GitHub using the same name as the local repository. The new repository is automatically set to private.
- Sets the local repository's remote URL to the new repository's remote URL.
- Pushes the local repository's contents to GitHub.
cd
s back to the root folder.- Repeats steps 2-7 for all remaining repositories in the root folder.
Follow these instructions:
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
- Navigate to github.com/settings/tokens
- Find the token for
hub
- Check the box for "delete_repo"
- Confirm the change by clicking the "Update token" button at the bottom
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.
Try push/pulling and see if GitHub asks you for your credentials.
The folder name does not matter.
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
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