Simplify Your Projects: How to Use GitHub Template Repositories

πŸš€ Tired of setting up projects from scratch and copying and pasting the same CI/CD workflow files over and over? No more rework! In this post, we’ll solve this problem once and for all using GitHub Template Repositories.

The Problem: Constant Rework

Every time you start a new project, you need to:

  1. βœ… Create the repository
  2. βœ… Configure .gitignore
  3. βœ… Add standard README.md
  4. βœ… Set up CI/CD workflows
  5. βœ… Copy linter configurations (ESLint, Prettier, etc.)
  6. βœ… Configure directory structure
  7. βœ… Add license files
  8. βœ… Configure issue templates
  9. βœ… Configure pull request templates
  10. βœ… And much more…

If you have 10 microservices to create, that means repeating this process 10 times. And if you need to update something? Good luck manually updating 10 repositories!

The Real Cost

Let’s do the math:

This is time you should be using to create value, not copying files.

The Solution: GitHub Template Repositories

Template Repositories are a native GitHub feature that allows you to create a “mold” for new projects. With one click, you can generate a new repository with all the structure, configurations, and files ready to go.

Main Benefits

βœ… Brutal time savings - From 1 hour to 30 seconds in project creation
βœ… Guaranteed consistency - All projects follow the same standards
βœ… Faster onboarding - New developers start with familiar structure
βœ… Centralized maintenance - Update the template and new projects start already updated
βœ… Built-in best practices - Force good practices from the first commit

How to Create a Template Repository

Step 1: Create the Base Repository

First, create a normal repository with all the structure you want to replicate:

BASH
my-node-template/
β”œβ”€β”€ .github/
β”‚   β”œβ”€β”€ workflows/
β”‚   β”‚   β”œβ”€β”€ ci.yml
β”‚   β”‚   β”œβ”€β”€ deploy.yml
β”‚   β”‚   └── security-scan.yml
β”‚   β”œβ”€β”€ ISSUE_TEMPLATE/
β”‚   β”‚   β”œβ”€β”€ bug_report.md
β”‚   β”‚   └── feature_request.md
β”‚   └── pull_request_template.md
β”œβ”€β”€ .vscode/
β”‚   β”œβ”€β”€ settings.json
β”‚   └── extensions.json
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.js
β”‚   └── __tests__/
β”‚       └── index.test.js
β”œβ”€β”€ .gitignore
β”œβ”€β”€ .eslintrc.js
β”œβ”€β”€ .prettierrc
β”œβ”€β”€ jest.config.js
β”œβ”€β”€ package.json
β”œβ”€β”€ README.md
β”œβ”€β”€ LICENSE
└── CONTRIBUTING.md
Click to expand and view more

Step 2: Make the Repository a Template

  1. Go to repository Settings
  2. In the General section, check Template repository
  3. Save changes

Done! Now your repository is a template.

Step 3: Use the Template

To create a new project from the template:

  1. Go to the template repository
  2. Click Use this template β†’ Create a new repository
  3. Define the name and settings of the new repo
  4. Click Create repository

In seconds, you have a new repository with the entire structure!

Examples of Useful Templates

1. Node.js API Template

PLAINTEXT
node-api-template/
β”œβ”€β”€ .github/workflows/
β”‚   └── ci.yml              # Lint, test, build
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ controllers/
β”‚   β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ middleware/
β”‚   └── index.js
β”œβ”€β”€ tests/
β”œβ”€β”€ .env.example
β”œβ”€β”€ .eslintrc.js
β”œβ”€β”€ .prettierrc
β”œβ”€β”€ jest.config.js
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ docker-compose.yml
└── README.md
Click to expand and view more

Included CI/CD Workflow:

YAML
name: CI

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '18'
      - run: npm ci
      - run: npm run lint
      - run: npm test
      - run: npm run build
Click to expand and view more

2. Python Microservice Template

PLAINTEXT
python-microservice-template/
β”œβ”€β”€ .github/workflows/
β”‚   β”œβ”€β”€ ci.yml
β”‚   └── deploy.yml
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ main.py
β”‚   └── routers/
β”œβ”€β”€ tests/
β”œβ”€β”€ .flake8
β”œβ”€β”€ .pylintrc
β”œβ”€β”€ pytest.ini
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ requirements-dev.txt
β”œβ”€β”€ Dockerfile
└── README.md
Click to expand and view more

3. React Frontend Template

PLAINTEXT
react-app-template/
β”œβ”€β”€ .github/workflows/
β”‚   └── ci.yml
β”œβ”€β”€ public/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ hooks/
β”‚   β”œβ”€β”€ pages/
β”‚   β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ utils/
β”‚   └── App.jsx
β”œβ”€β”€ .eslintrc.json
β”œβ”€β”€ .prettierrc
β”œβ”€β”€ vite.config.js
β”œβ”€β”€ tsconfig.json
└── package.json
Click to expand and view more

Template vs Fork: What’s the Difference?

Many people confuse Template with Fork. Here’s the difference:

Fork

Template

Use Template when: You want to start a new project based on existing structure
Use Fork when: You want to contribute or keep synced with the original

Advanced Template Features

1. Dynamic Variables in README

You can use placeholders that users replace:

MARKDOWN
# {{PROJECT_NAME}}

## Description
This project is {{PROJECT_DESCRIPTION}}.

## Installation
\`\`\`bash
git clone https://github.com/{{USERNAME}}/{{REPO_NAME}}
cd {{REPO_NAME}}
npm install
\`\`\`
Click to expand and view more

2. Initialization Scripts

Include an init.sh script that sets up the project:

BASH
#!/bin/bash
# init.sh

echo "πŸš€ Setting up new project..."

# Request project name
read -p "Project name: " PROJECT_NAME

# Update package.json
sed -i "s/{{PROJECT_NAME}}/$PROJECT_NAME/g" package.json

# Generate .env from example
cp .env.example .env

# Install dependencies
npm install

# First commit
git add .
git commit -m "chore: initial commit from template"

echo "βœ… Project $PROJECT_NAME successfully configured!"
Click to expand and view more

3. GitHub Actions for Validation

Include a workflow that validates initial setup:

YAML
name: Template Validation

on:
  push:
    branches: [main]

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Check for template placeholders
        run: |
          if grep -r "{{PROJECT_NAME}}" .; then
            echo "⚠️  Template placeholders still exist!"
            exit 1
          fi
      
      - name: Validate structure
        run: |
          required_files=".gitignore README.md package.json"
          for file in $required_files; do
            if [ ! -f "$file" ]; then
              echo "❌ Required file not found: $file"
              exit 1
            fi
          done
Click to expand and view more

Best Practices for Templates

1. Clear Documentation

Your README.md should explain:

MARKDOWN
# Node.js API Template

## πŸ“¦ What's included

- βœ… Express.js configured
- βœ… Jest for testing
- βœ… ESLint + Prettier
- βœ… GitHub Actions CI/CD
- βœ… Docker + docker-compose
- βœ… Recommended directory structure

## πŸš€ How to use

1. Click "Use this template"
2. Run `npm install`
3. Copy `.env.example` to `.env`
4. Customize configurations
5. Start developing!

## βš™οΈ Required configurations

- [ ] Update project name in `package.json`
- [ ] Configure environment variables in `.env`
- [ ] Add secrets on GitHub (if using CI/CD)
Click to expand and view more

2. Keep Updated

Outdated templates are worse than no template:

BASH
# Create a workflow for dependabot
# .github/dependabot.yml
version: 2
updates:
  - package-ecosystem: "npm"
    directory: "/"
    schedule:
      interval: "weekly"
Click to expand and view more

3. Multiple Templates per Stack

Organize templates by technology/purpose:

PLAINTEXT
my-org-templates/
β”œβ”€β”€ node-api-template/
β”œβ”€β”€ python-ml-template/
β”œβ”€β”€ react-spa-template/
β”œβ”€β”€ nextjs-app-template/
β”œβ”€β”€ docker-compose-template/
└── terraform-aws-template/
Click to expand and view more

4. Working Example Environment

The template should be functional out-of-the-box:

JSON
{
  "name": "example-project",
  "scripts": {
    "dev": "nodemon src/index.js",
    "test": "jest",
    "lint": "eslint .",
    "format": "prettier --write ."
  }
}
Click to expand and view more

After cloning, npm install && npm run dev should already work.

Combining Templates with Other Tools

Templates + Cookiecutter

For Python projects, combine with Cookiecutter:

BASH
cookiecutter gh:your-org/python-template
Click to expand and view more

Templates + Yeoman

For JavaScript, use Yeoman generators:

BASH
yo my-generator
Click to expand and view more

Templates + Terraform Modules

For infrastructure:

HCL
module "api_service" {
  source = "github.com/my-org/terraform-api-module"
  
  app_name    = "my-api"
  environment = "production"
}
Click to expand and view more

Real-World Use Cases

1. Consistent Microservices

Before:

After (with template):

2. New Project Onboarding

Before: 3-4 days setting up new project
After: 30 minutes using template

3. Hackathons and Prototypes

Use templates to start fast:

Limitations and Alternatives

Template Limitations

  1. Static snapshot - New projects don’t automatically receive template updates
  2. No synchronization - Template changes don’t propagate
  3. Manual customization - Still need to adjust some files

Alternatives

For keeping synchronized:

For total automation:

Conclusion: Less Setup, More Code

Template Repositories are one of GitHub’s most underestimated features. When well implemented, they:

Implementation Checklist

Next Steps

In the next video/post, I’ll show:

Useful Resources


Already using template repositories? Share in the comments how you use them! What template would be most useful for you?

#GitHub #Template #Productivity #DevOps #BestPractices

Advertisement

Comments

Start searching

Enter keywords to search articles

↑↓
↡
ESC
⌘K Shortcut