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.
How does it work?
The script is very simple. The script...
- Assumes all the repositories you want to make private are in 1 root folder.
cds 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.
cds back to the root folder.
- Repeats steps 2-7 for all remaining repositories in the root folder.
Follow these instructions:
1. Install Hub
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
- Navigate to github.com/settings/tokens
- Find the token for
- Check the box for "delete_repo"
- 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 -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.
$ 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.