Created
January 26, 2024 21:28
-
-
Save pmuellr/c473c9f981648f00cebe6ee3af3f0087 to your computer and use it in GitHub Desktop.
git-wt-create.js - print the command to create a git worktree given an issue number and branch name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const pathMod = require('node:path') | |
const PROGRAM = pathMod.basename(__filename) | |
const [issue, branch] = process.argv.slice(2) | |
if (!issue || !branch) { | |
console.log(` | |
Usage: ${PROGRAM} <issue #> <git branch name> | |
Prints the "git worktree" command to create a new worktree | |
given the issue number and branch name. The issue number | |
and branch name are used in creation of the new branch | |
name to check the branch out to, and the directory name | |
of the worktree. | |
`.trim()) | |
process.exit(1) | |
} | |
const prBranch = branch.replace(':', '/') | |
const branchBits = branch.split('/') | |
const branchSlug = branchBits[branchBits.length - 1] | |
const newBranch = `${issue}-${branchSlug}` | |
const path = `../kibana-${newBranch}` | |
const cmd = `git worktree add -b ${newBranch} ${path} ${prBranch}` | |
console.log(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment