DEV Community

Cover image for How to Use GitHub Repository Templates
GitProtect Team for GitProtect

Posted on • Edited on • Originally published at gitprotect.io

How to Use GitHub Repository Templates

Starting any project from a scratch can be frightening. Blank pages are scary for writers, as well as empty canvases for painters. Software developers are in a similar situation when they are setting up projects on GitHub. But there is an answer to this problem, it’s Repository Templates.

The usage of Repository Templates is especially beneficial when you create the same projects a number of times or work in a big team. Repository Templates is a GitHub feature released in June 2019, which makes work with GitHub more efficient and enjoyable. In this article, you will learn how to use and create GitHub repositories to help you with your daily tasks.

About repositories

A repository holds all of your project’s files and each file’s revision history. Within the repository, you may review and monitor your project’s progress. You may also provide collaborator access to other members in user-owned repositories. Thus, they can work on your project, as well. If a repo is controlled by an organization, you may provide access permissions to members of that organization to collaborate on it.

GitHub templates

There are more than just repos templates that could help you jump-start any GitHub static page project. They are:

  • Issue template, which is an ability to create the template of the structure of every new issue
  • Pull request template, which gives each team member the information on what to check while creating the pull request
  • Repository template, which is our today’s topic

Template repository vs. forking a repository

Using templates varies from directly forking a repo. The commit history is cleaned, and there is no link to the original repository. This indicates that your new repository has all the code but there is no history. It will be easier to track your changes, and your work will not be tied to the repository’s other forks. This might be handy to give the team members a well-organized template to support good practices or to provide oneself with a set of often-used resources.

GitHub template repository – benefits

  • Increases the speed of your routine tasks.
  • Allows you to concentrate on more important aspects of your work.
  • Makes configuration less manual.
  • Permits to use boilerplate code in multiple codebases.

Git template repository – features

  • Copy all of the files from the old repository to a new one.
  • Every template has a new /generated URL endpoint.
  • Share the repository template with your team or other GitHub users.

Creating a repository from a template

  1. Go to the GitHub.com/new
  2. Above the file list, choose your Repository template Creating a repository from a template
  3. Select whether you want to include all branches, not just the default one.
  4. Choose the owner.
  5. Add a name to the new repo and an optional description.
  6. Set the visibility of a repository.
  7. Click the “Create repository” button and voilà!

Creating a template repository

Before you start to use repository templates in your new project you have to create one. It is really simple. The ‘Template repository’ feature allows developers to identify a repository as a template, which consequently they can use to create new repositories that contain all the files and folders from the template repository. To do it follow these steps:

  1. Navigate to the repository’s home page on GitHub.com.
  2. Select Settings from the navigation under your repository name.
  3. Select the “Template repository” checkbox and that’s it. creating a template repository

Repository template using the GitHub CLI

Use gh repo create with no arguments to create a repository interactively. To establish a non-interactive remote repository, enter the repository name and one of the options –public, –private, or –internal. To clone the new repository locally, use the –clone option.

Specify the source directory with –source to establish a remote repository from an existing local repository. The name of the remote repository will be the same as the name of the source directory by default. To push any local commits to the new repository, use the –push option.

Why use the GitHub template repository over a project template

Many developers will likely raise this issue, and it is a reasonable one. The answer is simple: template repositories allow you to accomplish a lot, and they contain much more than just a code project template.

Your company can use a template repository to:

  • Copy the complete directory structure and files from the old repository to a new one.
  • Share the repository template with your team or other GitHub users.

Looking for the next article to read? Check how to clone using HTTPS in git.

✍️ Subscribe to GitProtect DevSecOps X-Ray Newsletter – your guide to the latest DevOps & security insights

🚀 Ensure compliant DevOps backup and recovery with a 14-day free trial

📅 Let’s discuss your needs and see a live product tour

Top comments (0)