正在创建一个以当前 git 分支为名称的文件夹

Creating a folder with the current git branch as the name

我正在寻找一种创建本地测试文件夹的方法,该文件夹代表分支名称,该分支名称应该是已检出的当前 git 分支。

例如,如果您在分支 feature/stable-test 中处理样式表,并且您 运行 一个编译代码的 g运行t 任务,而不是作为目标,您将得到 /stable-test/style.css.

我查看了 grunt-githash and grunt-gitinfo,但当我查询 <%= gitinfo.local.branch %> 时,它们 return 都是一个空对象。

git branch | grep "\*" | cut -d " " -f2 | xargs mkdir

将创建一个名为当前分支的文件夹。

由于您用 node.js 标记了这个问题,我想补充:

您可以使用像simple-git get the current branch or use child_process.exec这样的节点插件直接调用git。

# git branch
  autogenerated
* generated
  master

您会得到一个分支列表,当前分支是带星标的分支。 Select这一行,去掉前两个符号,用名字。