{"id":45374764,"url":"https://github.com/teles/new-branch","last_synced_at":"2026-02-28T03:56:56.501Z","repository":{"id":339086038,"uuid":"1160461070","full_name":"teles/new-branch","owner":"teles","description":"Generate and create standardized git branch names from a pattern.","archived":false,"fork":false,"pushed_at":"2026-02-21T14:06:41.000Z","size":356,"stargazers_count":2,"open_issues_count":5,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-21T20:44:25.950Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/new-branch","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/teles.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-18T00:53:52.000Z","updated_at":"2026-02-21T14:06:43.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/teles/new-branch","commit_stats":null,"previous_names":["teles/new-branch"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/teles/new-branch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teles%2Fnew-branch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teles%2Fnew-branch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teles%2Fnew-branch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teles%2Fnew-branch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teles","download_url":"https://codeload.github.com/teles/new-branch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teles%2Fnew-branch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29922071,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T19:37:42.220Z","status":"ssl_error","status_checked_at":"2026-02-27T19:37:41.463Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-02-21T16:03:25.170Z","updated_at":"2026-02-28T03:56:56.496Z","avatar_url":"https://github.com/teles.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# new-branch\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./logo.svg\" width=\"180\" alt=\"new-branch logo\" /\u003e\n\u003c/p\u003e\n\n\u003e “Explicit is better than implicit.”\n\u003e — The Zen of Python (PEP 20)\n\nA composable CLI to generate and optionally create standardized Git branch names using a pattern + transform pipeline.\n\n![demo](./demo.gif)\n\n[![CI](https://github.com/teles/new-branch/actions/workflows/ci.yml/badge.svg)](https://github.com/teles/new-branch/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/gh/teles/new-branch/branch/main/graph/badge.svg)](https://codecov.io/gh/teles/new-branch)\n\n---\n\n## Why\n\nKeep branch names consistent across your team using a declarative pattern language.\n\n---\n\n## Install\n\nRun without installing:\n\n```bash\nnpx new-branch\n```\n\nOr install globally:\n\n```bash\nnpm install -g new-branch\n```\n\n---\n\n## Usage\n\nGenerate a branch name:\n\n```bash\nnew-branch \\\n  --pattern \"{type}/{title:slugify;max:25}-{id}\" \\\n  --type feat \\\n  --title \"My task\" \\\n  --id STK-123\n```\n\nCreate the branch automatically:\n\n```bash\nnew-branch \\\n  --pattern \"{type}/{title:slugify}-{id}\" \\\n  --type feat \\\n  --title \"My task\" \\\n  --id STK-123 \\\n  --create\n```\n\n---\n\n## Pattern Language\n\nPatterns are composed of variables and ordered transforms.\n\nExample:\n\n```\n{type}/{title:slugify;max:25}-{id}\n```\n\n### Syntax\n\n```\n{variable:transform1;transform2:arg}\n```\n\n- Variables are wrapped in `{}`\n- Transforms run left-to-right\n- Multiple transforms are separated by `;`\n- Transform arguments use `:`\n\n---\n\n## Built-in Variables\n\n### Core Variables\n\n- `type`\n- `title`\n- `id`\n\n### Date Built-ins (derived from local system time)\n\n- `year` → YYYY\n- `month` → MM (zero padded)\n- `day` → DD (zero padded)\n- `date` → YYYY-MM-DD\n- `dateCompact` → YYYYMMDD\n\n### Git Built-ins (derived from current Git repository)\n\n- `currentBranch` → Current Git branch name (e.g. `main`, `feature/PROJ-123`)\n- `shortSha` → Short SHA of `HEAD` (e.g. `a1b2c3d`)\n- `repoName` → Repository directory name\n- `userName` → Git user name (`git config user.name`)\n- `lastTag` → Most recent Git tag (`git describe --tags --abbrev=0`)\n\n\u003e Note:\n\u003e\n\u003e - Git built-ins are resolved lazily and only when referenced in the pattern.\n\u003e - They are never prompted interactively.\n\u003e - When unavailable (e.g. outside a Git repository), they resolve to an empty string.\n\n#### Example with Git built-ins\n\n```bash\nnew-branch \\\n  --pattern \"{currentBranch}-{shortSha}-{type}-{title:slugify}\" \\\n  --type feat \\\n  --title \"Improve logging\"\n```\n\nExample output:\n\n```\nmain-a1b2c3d-feat-improve-logging\n```\n\n---\n\n## Built-in Transforms\n\n| Transform | Description                |\n| --------- | -------------------------- |\n| `slugify` | Convert to URL-safe slug   |\n| `lower`   | Convert to lowercase       |\n| `upper`   | Convert to uppercase       |\n| `camel`   | Convert to camelCase       |\n| `kebab`   | Convert to kebab-case      |\n| `snake`   | Convert to snake_case      |\n| `title`   | Convert to Title Case      |\n| `words:n` | Keep at most `n` words     |\n| `max:n`   | Truncate to `n` characters |\n\nAll transforms are pure functions and composable.\n\n---\n\n## Interactive Mode\n\nIf variables referenced by the pattern are missing, the CLI prompts for them by default.\n\nDisable prompts with:\n\n```bash\n--no-prompt\n```\n\n---\n\n## CLI Options\n\n| Option                    | Description                         |\n| ------------------------- | ----------------------------------- |\n| `-p, --pattern \u003cpattern\u003e` | Branch pattern                      |\n| `--type \u003ctype\u003e`           | Branch type                         |\n| `--title \u003ctitle\u003e`         | Task title                          |\n| `--id \u003cid\u003e`               | Task identifier                     |\n| `--create`                | Create branch using `git switch -c` |\n| `--no-prompt`             | Fail instead of prompting           |\n| `--quiet`                 | Suppress output                     |\n\n---\n\n## Project Configuration and precedence\n\nConfiguration for `new-branch` may come from several places. The CLI resolves the first _non-empty_ configuration it finds according to the following precedence (highest → lowest):\n\n1. CLI flags (explicit `--pattern`, `--type`, etc.)\n2. `.newbranchrc.json` (a repository-local JSON config file)\n3. `package.json` under the `new-branch` key\n4. Git config (`new-branch.pattern`) — local then global\n5. Interactive prompt (only if enabled and a value is still missing)\n\nThis means that if a higher-precedence source provides a non-empty value, lower-precedence sources are not consulted or merged.\n\nExamples\n\n1. `.newbranchrc.json` (preferred when present and non-empty):\n\n```json\n{\n  \"pattern\": \"{type}/{title:slugify}-{id}\",\n  \"types\": [\n    { \"value\": \"feat\", \"label\": \"Feature\" },\n    { \"value\": \"fix\", \"label\": \"Fix\" }\n  ],\n  \"defaultType\": \"feat\"\n}\n```\n\n2. `package.json` fallback:\n\n```json\n{\n  \"new-branch\": {\n    \"pattern\": \"{type}/{title:slugify}-{id}\",\n    \"defaultType\": \"fix\"\n  }\n}\n```\n\n3. Git config fallback (local takes precedence over global):\n\n```bash\ngit config --local new-branch.pattern \"{type}/{title:slugify}-{id}\"\ngit config --global new-branch.pattern \"{type}/{title:slugify}-{id}\"\n```\n\nNotes about `type` and `defaultType`\n\n- Order for resolving the branch `type` follows the SPEC behavior we implemented:\n  1. CLI `--type` (explicit flag) overrides everything.\n  2. `defaultType` from the selected configuration source is used next (if present).\n  3. If the project config declares exactly one `type` in `types[]`, that single type is used as a convenience.\n  4. If the type is still not resolved and interactive prompting is allowed, the CLI will prompt for it.\n  5. If the type is still missing and `--no-prompt` (or `prompt: false`) is in effect, the CLI will fail with a helpful error.\n\n- Validation: when a configuration source provides both `types[]` and `defaultType`, the `defaultType` must match one of the declared `types[].value`. If it does not, configuration validation will surface an error.\n\n- Interactive prompts: when `types[]` are present in the chosen project config, those entries are exposed as choices to the interactive `type` select prompt so users see and can pick project-defined types.\n\nTo remove the pattern from Git config:\n\n```bash\n# Remove from local repository\ngit config --unset --local new-branch.pattern\n\n# Remove from global config\ngit config --unset --global new-branch.pattern\n```\n\n---\n\n## Git Safety\n\nAfter rendering, branch names are:\n\n1. Lightly sanitized\n2. Validated via `git check-ref-format --branch`\n\nInvalid names cause the command to fail.\n\n---\n\n## Development\n\n```bash\npnpm install\npnpm test:run\npnpm build\n```\n\n---\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteles%2Fnew-branch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteles%2Fnew-branch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteles%2Fnew-branch/lists"}