Last Updated on November 8, 2024

Don’t forget to back up your GitHub source code to make your work secure and data accessible in any event of failure. Try GitProtect.io backup & DR software for GitHub.

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, and since then it has been making workflow more efficient and enjoyable. Why? Once created custom templates within your organization, you can simply select template repository instead of configuring a new one. In this article, you will learn how to use and create templates to help you with your daily tasks. 

What should you know 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. For that you can create a default branch, which is the primary branch where all changes are initially made and, which is often used as the main branch for development.

GitHub templates

There are more than just repos templates that could help you jump-start any GitHub static page project. Using them in GitHub repositories, for example, you can streamline development and collaboration processes, standardize production workflows, and encourage collaboration and maintainability.

So, GitHub templates can vary:

  • 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, ensuring a consistent project’s structure.

Get free trial

 GitHub template repository – top 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.
  • Enhances software development by streamlining the development and collaboration process, providing consistency, saving time and effort, facilitating onboarding, allowing for customization, and integrating with version control.

Git template repository – key features

  • Copy all of the files from the old repository to a new one.
  • Every template has a new /generate URL endpoint.
  • Share the repository template with your team or other GitHub users.
  • Ensure you have read and write permissions in the repository settings to enable GitHub Actions and GitHub Pages for publishing content.

Creating a repository from a template

The process starts from the main page of the repository.

  1. Go to the GitHub.com/new.
  2. Above the file list, choose your Repository template.
Create repository from a template
  1. Select whether you want to include all branches, not just the default one. 
  2. Choose the owner from the dropdown menu.
  3. Add a name to the new repo and an optional description.
  4. Set the visibility of a repository.
  5. Click “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. Using template repositories can significantly benefit an open-source project by providing a standardized structure, ease of customization, and improved visibility. To do it follow these steps:

  1. Navigate to the repository’s home page on GitHub.com.
  2. Select Settings from 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. After creating the repository, you can access the project page through the provided link.

GitHub backup guide

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.

Frequently Asked Questions

How to create and use a repository template?

Step 1. Create a new repo that you’d like to use as a template.
Step 2. Go to Settings of the repository and check the Template repository option.
Step 3. You can select the template under the Repository Template section when creating a new repo.

How do I create a template for issues in GitHub?

To create issue templates in GitHub, you can set up default templates for common issues, like bug reports or feature requests.

  1. In your repository, go to Settings -> Issues.
  2. Scroll to the Features section and select Set up templates.
  3. You can either use predefined templates or create custom ones:
    • create a .github/ISSUE_TEMPLATE directory in the root of your repository
    • add markdown files (e.g., bug_report.md, feature_request.md) with specific formats for each type of issue.

The described templates can guide users in providing structured information when opening issues.

How do I add files to GitHub pull requests?

Adding files to an existing pull request involves making additional commits to the same branch from which the pull request was initially created.

Step 1. Make sure you are on the branch with the open pull request.
Step 2. Add new files or modify existing ones. For example:

git add <file1><file2>
git commit -m "Add new files to pull request."
git push origin <branch-name>

Step 3. The pull request will update with the new files and changes automatically.

How to use the Git commit template?

With Git commit templates, it’s easier to standardize all commit messages for consistency and readability.

Create a file with the template you want (e.g., .gitmessage.txt) and add placeholders for your commit structure. For example:

# Commit Title: Summary (Fix login bug, etc.)
#
# Description:
# - Detail 1
# - Detail 2
#
# Closes issues #

Configure Git to use this template:

git config --global commit.template ~/.gitmessage.txt

When you run git commit, the template will prepopulate in your editor.

How to create a GitHub repository from an existing directory?

To create a GitHub repo from an existing directory on your local machine:

  • Navigate to your project’s directory.
cd /path/to/your/project
  • Initialize Git and add all files.
git init
git add .
git commit -m "Initial commit"
  • Create a new repository on GitHub without adding a README, .gitignore, or license. These are already in your local repo.
  • Link the local repository to the GitHub remote and push.
git remote add origin https://github.com/username/repo-name.git
git push -u origin main

Is it better to fork or branch in Git?

It depends… If you don’t have access to the main repository or want to maintain an independent copy, it’s better to fork.

However, a branch is a far better option when working within a single repo, especially for collaborative development. Branching is lightweight and ideal for implementing features or fixes that will eventually be merged into the main project.

Before you go:

🔎 Check out 5 top-notch arguments to start backing up your GitHub repositories and metadata

🐙 Do you think you don’t need a backup if you use GitHub/GitLab/Bitbucket? We’ve already busted this myth in our DevSecOps MythBuster blog post… Don’t miss it out!

👀 Find out which infamous GitHub-related incidents took place in 2023, don’t stay in the dark!

📚 Read our blog post – Your own Git backup script vs. repository backup software, –  and see which backup option better suits your needs

✍️ Subscribe to GitProtect DevSecOps X-Ray Newsletter and stay informed about the latest developments in DevSecOps

📅 Schedule a live custom demo and learn more about GitHub repository and metadata backup

📌 Or try GitProtect backups for the GitHub environment and start protecting your critical GitHub data in one go

Comments are closed.

You may also like