GitHub Repositories: Private & Public Guide
Milestone 12: Creating Private and Public Repositories - Your GitHub Guide 🚀
Hey guys! Welcome back to the world of collaborative research! In this milestone, we're diving deep into how to manage your code and projects using GitHub repositories – specifically, focusing on private and public ones. This is super important because sometimes you want to keep things under wraps (like a draft paper), and other times you want to share your work with the world. Let's get started!
Task: Creating Private Repositories (Easy Peasy! 🟢)
Why this matters:
Sometimes you need privacy, right? Maybe you're working on a paper draft before it's ready for prime time. Or perhaps you have sensitive data or code that's not quite ready for public consumption. This is where private repositories come in handy. They let you work on things in secret until you're ready to share.
Detailed Steps:
Step 1: Create a PRIVATE Repository
- Head over to github.com and click that shiny green "New" button. You can also use the "+" icon in the top right, then select "New repository," or just go to <github.com/new>. Get ready to build something new!
- Repository name: Give it a cool name, like
private-project
or whatever makes sense for your work. - Important: Select Private visibility. This is like putting a lock on your project, so only you and the people you invite can see it.
- Check the box "Add a README file." This is a good practice for all your repos.
- Click "Create repository." Boom! You've got your own private space.
- Now, let's create a new issue. This issue should stay private. For example:
# Team Notes on Reviewer Comments
Reviewer 2 is being difficult again.
TODO: Fix methodology they complained about
Step 2: Test Visibility with Your Partner
- Share your GitHub username with your partner (the collaborator).
- Partner searches for your PRIVATE repo:
- Type:
user:PARTNER_USERNAME private
(replacePARTNER_USERNAME
with your partner's username) - Press Enter – your private repo should NOT appear in the search results (unless your partner is a collaborator on the repository). If it doesn't show up, you're golden!
- Type:
Expected Results:
- Private repository: Effectively hidden from anyone who's not a collaborator. It's like a secret clubhouse for you and your team.
Discussion:
When would you use private vs. public repos in your research? Let's chat about it! Share your thoughts in the comments.
When done: Comment /done 12
in the tracking issue or try the hard version of this milestone.
Task: Creating Semi-Private Repositories (Advanced! 🔴)
Why this matters:
Imagine this: You've published a preprint, and you're getting reviews. You want to keep the discussion among collaborators secret, but you still want a public GitHub repo to maintain proper version control. Here's how to do it!
Detailed Steps:
To accomplish this, we'll create a public repo that mirrors our private repo. We'll sync up both versions from time to time.
Step 1: Create a PUBLIC Repository
- Go to github.com and click that shiny green "New" button again! Or use the "+" icon, then select "New repository," or go to <github.com/new>.
- Repository name: Give it a name like
public-project
or something fitting. - Important: Do not click any of the boxes, we need a fully empty repo. We will build it later.
- Leave visibility as "Public." This means anyone can see it.
- Click "Create repository."
Step 2: Link Your Public Repository
- Go to your private repository.
- Open a Codespace (if you remember from Milestone 11), or do it locally (which is also perfectly fine!).
- Open a terminal:
Terminal
→New Terminal
- Add your public repo as a remote: This tells your private repo about the public one.
git remote add public https://github.com/YOURUSERNAME/public.git
Replace `YOURUSERNAME` with your GitHub username.
5. **Verify it worked:**
```bash
git remote -v
You should see both "origin" (which is your private repo) and "public" (your public repo) listed.
- Push the content:
- First,
git push origin main
, to make sure that the contents from local are up-to-date toorigin main
- Then,
git push public main
- First,
Step 3: Authenticate to Push to Another Repo
First, we need to authenticate.
unset GITHUB_TOKEN
gh auth login --scopes repo --git-protocol https --web --hostname github.com
Then: gh auth setup-git
Step 4: Push to the Public Repo
git push public main
Now, all the content from your private repo is public, but your PRs and issue discussions stay private. So, anything you want to keep private needs to remain in an Issue or PR.
Important:
If you ever commit some content in git, even if you change it later, those private things can resurface. One option for that is to use git merge --squash
for the public branch/repo that hides all intermediate changes, but we won't go into more detail here. Feel free to ask, though! This is some advanced stuff!
When done:
Comment /done 12
in the tracking issue. You're doing great!