Generating A Git Repo
The sketch repo command allows you to generate a new git repository, starting from a preset stored in one of your configuration files.
A git preset uses (or defines) a preset for its gitignore file and, optionally, for pre-commit, as well as a list of templates that will be generated inside the root of the new repo when the command is triggered.
# Gitignore presets
gitignore_presets:
# Can be a string
base:
content: |
*.env
dist
# Or a list of strings
ts:
extends_presets:
# When being merged, the new entries are placed at the top
- base
content:
- "*.tsBuildInfo"
- node_modules
# Pre-commit presets
pre_commit_presets:
# Commonly used repo
base:
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.30.0
hooks:
- id: gitleaks
# Hooks specific to typescript projects
typescript:
# Extending the base preset
extends_presets:
- base
repos:
- repo: local
hooks:
- id: oxlint
name: oxlint
entry: oxlint
language: system
files: '\.svelte$|\.js$|\.ts$'
types: [file]
# Git presets
repo_presets:
ts_package:
workflows:
- file_name: my_workflow.yaml
# Preset ID
id: extended
# License file to generate
license: Apache-2.0
# Selecting a preset
gitignore: ts
pre_commit: typescript
Adding Workflows
We can also include some Github workflows by using their presets:
workflows:
- file_name: my_workflow.yaml
# Preset ID
id: extended
Adding Templates
We can use the with_templates setting to add a group of templates to a git preset. Let's say that we want to automatically generate a basic docker setup whenever we use this preset:
# We define a template in a file or in a config file...
templates:
dockerfile: |
FROM node:23-alpine
COPY . .
EXPOSE {{ docker_dev_port | default(value=5173) }}
CMD ["npm", "run", "dev"]
# Templating presets
templating_presets:
dockerfile:
context:
# Group context
docker_dev_port: 9530
# List of templates
templates:
# Single template
- output: Dockerfile
template: dockerfile
# ...and then we add it to a preset
# Git presets
repo_presets:
ts_package:
workflows:
- file_name: my_workflow.yaml
# Preset ID
id: extended
# License file to generate
license: Apache-2.0
# Selecting a preset
gitignore: ts
pre_commit: typescript
# Templates that will be generated with this preset
# starting from the new repo's root
with_templates:
- preset_id: dockerfile
# Adding context
context:
docker_dev_port: 9530
Example
Starting from the config from above, we can run this command:
sketch repo --preset ts_package repo
To get this tree output:
├── Dockerfile
├── .github
│ └── workflows
│ └── my_workflow.yaml
├── .gitignore
├── LICENSE
└── .pre-commit-config.yaml
ℹ️ With cli flags, we can override the
gitignoreandpre-commitpresets, as well as adding new templates to generate when the preset is being used.
pre-commit-config.yaml output
repos:
- repo: local
hooks:
- id: oxlint
entry: oxlint
files: \.svelte$|\.js$|\.ts$
language: system
name: oxlint
types:
- file
- repo: https://github.com/gitleaks/gitleaks
rev: v8.30.0
hooks:
- id: gitleaks
gitignore output
*.env
dist
*.tsBuildInfo
node_modules