Git 参数别名不起作用

Git Parameter Alias not working

所以我一直在尝试为我在 Git 中所做的事情创建一个别名:基于我的开发分支创建一个新分支但不跟踪它。我在命令提示符中输入的代码是:

Git checkout –b branchname --no-track origin/develop

现在,我想把它变成一个别名,所以我正在尝试:

git config --global alias.newBranch "!git checkout -b  --no-track origin/develop"

然而,当我输入 "git newBranch test" 时,我得到了这个:"fatal: 'test' is not a commit and a branch 'test' cannot be created from it"

我在这里错过了什么?

Git 按字面解释别名。即,当扩展别名 git 时 进行简单的文本替换。在您的情况下,如果您 运行 git newBranch test git 将其扩展为命令

!git checkout -b  --no-track origin/develop test

这肯定不是你想要的。你需要一个shell函数来传递参数:

git config --global alias.newBranch "!f() { git checkout -b  --no-track origin/develop; }; f"