How to Create and Use a GitHub Repository Template
Managing reusable project setups becomes easy with GitHub repository templates. This guide will walk you through creating, configuring, and using a repository template on GitHub.
1. Create the Repository on GitHub
- Go to your GitHub account.
- Click on the New Repository button.
-
Fill out the repository details:
- Repository Name: Choose a name, e.g., devcontainer-python-template.
- Description: Add an optional description of the repository's purpose.
- Visibility: Select Public or Private depending on your preference.
- Owner: (Optional) If you're creating the repository under an organization, choose the appropriate owner (your account or an organization).
- Initialize with a README: Check the box for Initialize this repository with a README (optional).
- License: (Optional) Choose a license for the repository, such as MIT, GPL, or any other license that suits your project.
Click Create Repository.
2. Configure the Repository as a Template
Once the repository is created:
- Navigate to the repository's Settings.
- Scroll down to the Template repository section.
- Check the box for Template repository.
- Optional: Enable the option to Automatically delete head branches after pull requests are merged. This helps keep your repository tidy by automatically removing branches that have been merged, so you don't need to manually delete them.
- Save your changes.
3. Add Your Files to the Repository
Clone the repository locally:
git clone https://github.com/jdevto/devcontainer-python-template.git
cd devcontainer-python-template
It's always a best practice to create a branch and work from it.
git branch contents
git checkout contents
Now, add or edit any files that you need for your project. You can modify the existing template files, or add new ones as required.
4. Push the branch to GitHub
- Execute
git add --all
git commit -m "feat: update template contents" \
-m "add contents to the template"
git push origin contents
5. Create a Pull Request (PR)
Navigate to Your Repository on GitHub
- Visit your repository on GitHub.
Go to the "Pull Requests" Tab
- Click on the "Pull Requests" tab at the top of the repository page.
Create a New Pull Request
- Click the "New Pull Request" button.
Select Branches for the PR
- Base branch: Choose the branch you want to merge into (e.g., main or production).
- Compare branch: Select the branch you just pushed (e.g., contents).
Open Pull Request Creation
- Click "Create pull request".
Review the Changes
- Review the list of commits and files changed to ensure everything looks correct.
Add a Title and Description
Provide a concise and descriptive title (e.g., feat: update template contents).
Add a description with any necessary details (e.g., reasons for changes, references to issues, etc.).
Finalize the Pull Request
- Click "Create pull request" again to confirm.
Review and Approve the PR
- Self-review your changes or request reviews from teammates.
Merge the Pull Request
- Once everything looks good, navigate to the PR and click "Merge Pull Request".
- Confirm the merge by clicking "Confirm merge".
6. Post-Check and Final Steps
After completing the merge, here are the steps to verify everything is in order:
Review the Repository:
- Ensure the files and changes have been correctly added and merged.
- Verify the template repository is functioning as expected.
Check the Repository on GitHub:
- Navigate the repository devcontainer-python-template.
- Ensure all files are present, and the template is set up correctly.
Test the Template:
- Test creating a new repository from your template to ensure everything works as expected.
- Verify that the repository is pre-configured and ready for use by other users.
Optional - Clean Up:
- If you’ve set up automatic branch deletion, make sure the feature is working correctly to remove branches once the PR is merged.
- Review any other post-merge actions like re-checking documentation or confirming changes across other projects.
Here is a repository I created by following the steps in this article:
Top comments (0)