Github is widely used for code management, tracking changes and version control. It’s a very useful website and cloud-based service making a lot of things easier for developers and other IT professionals.
According to a recent official update, GitHub has introduced ‘Template repository’ which can be used to manage and share directory structure and boilerplate code across the project easily. The service is based on a similar concept as ‘Boilr’ and ‘Cookiecutter’.
How to create a GitHub template repository?
As the name suggests, Template repository allows developers to mark a repository as a template. They can use this repository later for creating new repositories with all the template’s files and folders.
You can either create a new template repository or mark an existing one as a template with admin privileges, it’s completely up to you. Just go to the Settings page and click on ‘Template repository’ checkbox.
After creating the template repository, anyone with the required access will be able to generate a new repository with same directory structure and files via ‘Use this template’ button.
You can see all of your owned templates, have access to, or have used in previous projects when you create a new repository through ‘Choose a template’ drop-down. Furthermore, all the template repo will have a new URL ‘/generate’ endpoint that makes distributing them a lot easier. You just have to redirect your template users to this endpoint.
Templating is similar to cloning a repository with a restriction such as it must not retain the repository history. The users should have a fresh new project with an initial commit only.
“This is a part of something which could become a very powerful pattern: community-wide templates which include many best practices in a single commit,” said a HackerNews user. You can do the following things with the template repository now:
- Pre-commit hooks for linting/formatting and unit tests.
- Configure Basic CI pipeline with at least build, test and release/deploy phases.
- Configure Package installation for the frameworks you want.
- Configure Container/VM for the languages you want to enable cross-platform and future-proof development.
- Documentation to get started with it all.
As of now, the service is very basic but GitHub has plans add more capabilities to all of the template types—repositories, issues and pull requests. They want us to help spend less time repeating work so we can get back to building new things. The current version also has detailed documentation that will help junior developers and beginners to get started easily.