A Git CLI tool to create new repositories or branches from predefined templates.
Project description
Git Template CLI Tool 🚀
Overview
The git-template-cli tool is a powerful command-line interface designed to streamline your development workflow by allowing you to quickly generate new projects, components, or services from predefined templates. Say goodbye to repetitive manual setups and boilerplate code!
Whether you're starting a new React component, a Python microservice, or just a basic project structure, git-template-cli can set it up in seconds, ensuring consistency across your codebase.
Features
- Quick Project/Component Generation: Instantly create new items from pre-configured templates.
- Placeholder Replacement: Automatically replaces template-specific placeholders (like component names, project names, or years) with your provided values.
- Standardized Structure: Enforces consistent project and component structures across your team.
- Git Integration: Optionally creates a new Git branch and stages the generated files automatically.
- Extensible: Easily add your own custom templates to suit your specific needs.
- Interactive Welcome: A friendly welcome screen guides new users.
Installation
1. Via PyPI (Recommended)
The easiest way to install git-template-cli is directly from PyPI:
pip install git-template-cli
This command will install the tool and make the git template command available in your terminal.
OR
2. From Source (if pip not working)
If you prefer to install from the source code (e.g., for development or contributing), follow these steps:
- Clone the repository:
git clone [https://github.com/BUBU-Git/git-template-tool.git](https://github.com/BUBU-Git/git-template-tool.git) # Replace with your actual GitHub URL cd git-template-tool
- Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate
- Install dependencies:
pip install click
- Install the tool in editable mode (for development):
pip install -e .
- Add the
git-templatewrapper to your PATH (if not usingpip install -e .): If you did not usepip install -e .(which sets up the entry point automatically), you'll need to manually ensure thegit-templatewrapper script is executable and in your system's PATH.chmod +x git-template
Then, add the directory containinggit-templateto your shell's PATH. For example, in your~/.bashrcor~/.zshrc:export PATH="/path/to/your/cloned/git-template-tool:$PATH" # After editing, run: source ~/.bashrc (or ~/.zshrc)
Usage
Once installed, you can invoke the tool using git template.
Welcome Screen
Running git template without any arguments will display a friendly welcome screen with available commands:
git template
(Press Enter to continue after the welcome screen)
Listing Available Templates
To see a list of all templates you can use:
git template list
Example Output:
Available templates:
- basic
- python-service
- react-component
Creating a New Item from a Template
To create a new project, component, or service from a template:
git template create <template-name> <new-item-name> [OPTIONS]
<template-name>: The name of the template you want to use (e.g.,react-component,basic,python-service).<new-item-name>: The desired name for your new item (e.g.,MyButton,MyNewProject,UserAuthService). This name will be used to create a new directory and replace placeholders within the template files.
Options:
--path <directory>,-p <directory>: Specifies the destination directory where the new item should be created. Defaults to the current working directory.- Example:
git template create react-component MyFeatureComponent --path src/components
- Example:
--no-git-add: Do not automaticallygit addthe newly created files.--no-git-branch: Do not automatically create a new Git branch for the new item.
Examples:
- Create a new React component named
MyAwesomeButtonin the current directory:git template create react-component MyAwesomeButton
- Create a new basic project named
MyNewWebsitein a~/projectsfolder (assuming it exists):git template create basic MyNewWebsite --path ~/projects
- Create a Python service
LoggerServicewithout creating a new Git branch:git template create python-service LoggerService --no-git-branch
Adding Your Own Templates
You can easily extend git-template-cli by adding your own custom templates.
-
Locate the
templatesdirectory: If installed via PyPI, this directory will be within your Python's site-packages. For simpler management, you can configure the tool to look for templates in a custom location (future enhancement, or you can fork and modifyTEMPLATE_BASE_DIRincli.pyfor now). For development/source installation, thetemplatesdirectory is directly in your cloned repository's root:git-template-tool/templates/. -
Create a new template directory: Inside the
templates/directory, create a new folder named after your desired template (e.g.,my-custom-template).git-template-tool/templates/ ├── my-custom-template/ │ ├── src/ │ │ └── index.js │ └── README.md └── ... (existing templates) -
Populate your template: Add all the files and subfolders that should be part of your template inside
my-custom-template/. -
Use Placeholders (Optional but Recommended): You can include placeholders in your template files that will be automatically replaced when
git template createis used.- Recommendation: For now, the tool looks for placeholders that match the template's general purpose and the
new-item-name.- For
react-component:COMPONENT_NAME(PascalCase),component_name_kebab(kebab-case). - For
python-service:SERVICE_NAME(as provided),service_name_snake(snake_case). - For
basic:PROJECT_NAME(as provided),LICENSE_TYPE(hardcoded as "MIT License"),YEAR(current year).
- For
- You'll need to update the
placeholdersdictionary insrc/git_template_cli/cli.pyto define how your custom template's placeholders should be replaced. For example:# In src/git_template_cli/cli.py, inside the 'create' function's placeholders dict "my-custom-template": { "MY_TEMPLATE_VAR": new_item_name, "another_var_kebab": kebab_case(new_item_name) }
- Recommendation: For now, the tool looks for placeholders that match the template's general purpose and the
Contributing
We welcome contributions! If you have ideas for new features, templates, or bug fixes, please open an issue or submit a pull request on the GitHub repository.
License
This project is licensed under the MIT License - see the LICENSE file for details.
About The Author
Developed by BUBU
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file git_template_cli-0.1.1.tar.gz.
File metadata
- Download URL: git_template_cli-0.1.1.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
959d3a824b7c6bc34bc72bbe5c23054affc58fd1182e8eeb389db4aac1647f39
|
|
| MD5 |
1ed200ba3426544efe1e21c6efd4b8dc
|
|
| BLAKE2b-256 |
3a5ee141e98163d7c3bb679d55e0f34d337aebaa5772c248506ba16612e14fa4
|
File details
Details for the file git_template_cli-0.1.1-py3-none-any.whl.
File metadata
- Download URL: git_template_cli-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85fc647c11381ddd6cba28dcb96be31b57be39ea5e8f52aec766c136634aa16d
|
|
| MD5 |
37510314c2591103510d3add693abc36
|
|
| BLAKE2b-256 |
eaa74f9b3fef64f55e82b4ab456bb535961f12fad48e1279c000b25be54ca29c
|