Skip to content

Instantly share code, notes, and snippets.

@pmuellr
Created January 26, 2024 21:28
Show Gist options
  • Save pmuellr/c473c9f981648f00cebe6ee3af3f0087 to your computer and use it in GitHub Desktop.
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
#!/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