Skip to main content

A Git CLI tool to create new repositories or branches from predefined templates.

Project description

Git Template CLI Tool 🚀

Banner

Git Template CLI Tool Banner PyPI - Version PyPI - Python Version License: MIT

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:

  1. 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
    
  2. Create and activate a virtual environment:
    python -m venv venv
    source venv/bin/activate # On Windows: .\venv\Scripts\activate
    
  3. Install dependencies:
    pip install click
    
  4. Install the tool in editable mode (for development):
    pip install -e .
    
  5. Add the git-template wrapper to your PATH (if not using pip install -e .): If you did not use pip install -e . (which sets up the entry point automatically), you'll need to manually ensure the git-template wrapper script is executable and in your system's PATH.
    chmod +x git-template
    
    Then, add the directory containing git-template to your shell's PATH. For example, in your ~/.bashrc or ~/.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
  • --no-git-add: Do not automatically git add the newly created files.
  • --no-git-branch: Do not automatically create a new Git branch for the new item.

Examples:

  1. Create a new React component named MyAwesomeButton in the current directory:
    git template create react-component MyAwesomeButton
    
  2. Create a new basic project named MyNewWebsite in a ~/projects folder (assuming it exists):
    git template create basic MyNewWebsite --path ~/projects
    
  3. Create a Python service LoggerService without 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.

  1. Locate the templates directory: 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 modify TEMPLATE_BASE_DIR in cli.py for now). For development/source installation, the templates directory is directly in your cloned repository's root: git-template-tool/templates/.

  2. 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)
    
  3. Populate your template: Add all the files and subfolders that should be part of your template inside my-custom-template/.

  4. Use Placeholders (Optional but Recommended): You can include placeholders in your template files that will be automatically replaced when git template create is 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).
    • You'll need to update the placeholders dictionary in src/git_template_cli/cli.py to 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)
      }
      

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

git_template_cli-0.1.1.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

git_template_cli-0.1.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

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

Hashes for git_template_cli-0.1.1.tar.gz
Algorithm Hash digest
SHA256 959d3a824b7c6bc34bc72bbe5c23054affc58fd1182e8eeb389db4aac1647f39
MD5 1ed200ba3426544efe1e21c6efd4b8dc
BLAKE2b-256 3a5ee141e98163d7c3bb679d55e0f34d337aebaa5772c248506ba16612e14fa4

See more details on using hashes here.

File details

Details for the file git_template_cli-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for git_template_cli-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 85fc647c11381ddd6cba28dcb96be31b57be39ea5e8f52aec766c136634aa16d
MD5 37510314c2591103510d3add693abc36
BLAKE2b-256 eaa74f9b3fef64f55e82b4ab456bb535961f12fad48e1279c000b25be54ca29c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page