GitHub Private Repository: Managing Private Repositories

By Sruthy

By Sruthy

Sruthy, with her 10+ years of experience, is a dynamic professional who seamlessly blends her creative soul with technical prowess. With a Technical Degree in Graphics Design and Communications and a Bachelor’s Degree in Electronics and Communication, she brings a unique combination of artistic flair…

Learn about our editorial policies.
Updated March 7, 2024

A complete study of the usage and administration of a GitHub Private Repository along with its features. Learn to quickly manage Private Repositories from here:

About GitHub Repository:

A repository in GitHub contains your project’s source code and its revision history. You can collaborate on the project’s work within the repository.

A repository in GitHub can be owned individually or the ownership can be shared with other people. Access to a repository can be restricted based on the repository’s visibility, either Private or Public.

Users can grant collaborators access to others for collaborating on their repositories. For repositories owned by the organization, they can give the organization members access to collaborate on the project.

GitHub Private Repository – A Simple Guide

GitHub Private Repository

GitHub is free for personal user accounts and organizations with unlimited public and private repository support, with differences in limited feature set support for private repositories.

Check out GitHub’s products – GitHub Docs for a look at the pricing and features of various GitHub products.

Repositories in GitHub can manage your work and also collaborate with your team using the below:

  • Use of issues to report defects and organize tasks and more.
  • Use PR (Pull Requests) to propose and make changes to your repository.
  • Use the project boards to organize your tasks and prioritize them.

Suggested Read =>> GitHub REST API Tutorial – REST API Support In GitHub

GitHub Repository Visibility

Repositories in GitHub can have two visibilities to restrict access, which is either public or private.

When a repository is created, you can choose it to be either public or private. With the GitHub Enterprise Cloud product, companies have the option to utilize GitHub in the cloud and can also have internal visibility that is like a public view within their managed site for the company.

As you login into GitHub, go to the Repositories, tab and select New.

Select New
Select New

Public repositories are visible and accessible to everyone on the internet.

Private repositories are visible and accessible to you and the people you give access to. Select the Private option to create a private repository.

In this article, we will look at some settings that we can set up in a private repository as an owner of the repository.

Managing Private Repository Settings

In this section, we will look at the most commonly used settings of the private repository owned by a personal user account or organization owner.

#1) Rename the Repository

To rename the repository, go to the repository Settings tab -> General section. Type a new name and click on Rename.

Rename the repository

#2) Create a Repository from a Template

We can create a new repository with the same directory structure as an existing repository. You can create a new repository from a template.

Enable the template repository option from the repository settings under the General section.

Create a repository from a template

Go to the main repository area and create a New repository. Select the Repository template while creating the new repository.

create a New repository

#3) Providing Access to the Private Repository owned by a Personal User Account

A repository owned by a personal user account has two permissions only, which are Owner and Collaborator. Under repository settings, go to Access -> Collaborators to add the collaborators.

Owners of the repository have full control over the repository, which also includes the DELETE activities.

Collaborators have pull, which reads contents from the repository, and push, which is written, to the repository.

#4) Providing Access to the Private Repository owned by the Organization

Under Organization, go to the People tab to add members.

A repository owned by an organization has the following roles:

  • Read: For non-code contributors
  • Triage: For contributors to manage issues, discussions, and PRs without write access to the code
  • Write: For contributors who need to push code to the repository
  • Maintain: For contributors to manage the repository but without the delete access to the repository
  • Admin: Contributors who need full access to the code including access to destructive actions like deleting the repository. Recommended is to have at least 2 admins.
Providing access to the private repository owned by organization

Custom roles can also be created as per the project needs.

#5) Enabling Features

As a repository owner or organization admin, you can enable features like issues, discussions, wikis, and projects. From the settings of the repository, you can enable or disable the features.

Enabling features - GitHub Private Repository

#6) Make a Public Repository Private

To change the visibility of the public repository to private, go to the repository Settings tab -> General section

Make a public repository private

Under Danger Zone, select the button Change visibility -> Change to private.

Danger Zone

Other options under Danger Zone

The other options for the repository under Danger Zone are:

  • Disable branch protection rules: Whether collaborators can push to the branch.
  • Transfer ownership: To another user or an organization
  • Archive repository: Make the repository read-only for all users. You can also unarchive the archived repository from Danger Zone itself
  • Delete repository: Will permanently delete the repository and cannot be undone
Other options under Danger Zone - GitHub Private Repository

#7) Restoring a Deleted Repository owned by Personal User Account

A repository that is deleted can be restored within 90 days. If the repository was part of the fork, then it cannot be restored unless it is detached.

To restore the repository, go to your Profile -> Settings. In the “Code planning, and automation” section of the sidebar select Repositories. Under Repositories click on Deleted Repositories.

click on Deleted repositories - GitHub Private Repository

Next to the repository, click on the Restore button to restore the repository.

#8) Restoring a Deleted Repository owned by the Organization

To restore a deleted private repository that was owned by the Organization go to the organization settings. In the left sidebar, click on Deleted Repositories under the Archive section.

Restoring a deleted repository

Click on the Restore button to restore the deleted repository.

Creating Personal Access Token

An alternative to using passwords for authentication is to create a Personal access token which can be used in CLI or while using the GitHub API. The Personal access token should also be used in CI/CD tools like Jenkins while using the SCM checkout step for authentication instead of passwords to your private repositories.

You can create Fine-grained or Classic tokens. It is advisable to generate fine-grained tokens. Otherwise, with classic tokens, you will have access to all the repositories by default, including those in your personal user account.

To create Fine-grained tokens, go to your Profile -> Settings and click on Developer Settings. Under Personal access tokens, select Fine-grained tokens. Click on Generate new token.

Creating Personal access token - GitHub Private Repository

Select the repository access for this token.

Select the repository access for this token - GitHub Private Repository

Click on Generate token once done.

Also Read => GitHub Tutorial For Developers

Frequently Asked Questions

1. What is a private repository in GitHub?

A repository in GitHub contains a project’s source code and its revision history. Access to every repository can be restricted by choosing its visibility i.e., Public or Private. As all are aware, Public repositories are available to everyone using GitHub, whereas Private repository is accessible only to the owner and to the people it is shared with.

2. Are GitHub private repositories free?

With GitHub Free for personal accounts and organizations, you get and can work with unlimited private repositories with limited features.

3. How do I import a private repository from GitHub?

Importing a private repository from GitHub can be done using the GitHub Importer. But this is not suitable for all types of imports especially if the code to be migrated resides in the private network.

The preferred option is through the command line (CLI) using the following steps:

Create a GitHub Organization Or a Private Repository
Make a “bare” clone of the repository which needs to be imported. This creates a full copy of the data, but without a working directory, which cannot be used for editing files.
git clone –bare https://.git
Push the cloned repository using the “mirror” option, which will push the branches and tags as well
git push –mirror https://Github-URL.git
Remove the local repository as needed

4. What is the difference between a Repository and a Project?

The repository is explained earlier in this article. Whereas a project helps the teams organize and prioritize your work items. Roadmaps and release checklists can also be created along with custom workflows for these work items can be created.

5. Who can view or work on a Private Repository?

As mentioned above, the private repository can only be seen by the owner of the repository or the people with whom it is shared.


Recommended Reading => A Complete Review of New Beta Features – GitHub Projects

Conclusion

In this article, I have highlighted the details on usage and administering a GitHub private repository and the features around it.

It is very important to administer the private repositories since all of your project information is on the cloud and also the need to secure the same.

Was this helpful?

Thanks for your feedback!

Leave a Comment