配置 git 以始终使用用户名作为分支前缀
Configure git to always prefix branches with user name
我的 .gitconfig br = checkout -b
中有以下别名,因此 git br feature
创建并检出一个名为 feature
的分支
不过,我真正想要的行为是 git br feature
创建一个分支 wheresrhys/feature
。
如何使用连接在 git 别名中创建所需的名称?
如果您 运行 git 来自类 Unix shell,常见的技巧是在您的别名定义中使用 shell 函数。在您的 .gitconfig
中添加以下内容即可。
[alias]
br = "!f() { git checkout -b wheresrhys/; }; f"
关于感叹号或感叹号,git config
文档注释
If the alias expansion is prefixed with an exclamation point, it will be treated as a shell command. For example, defining alias.new = !gitk --all --not ORIG_HEAD
, the invocation git new
is equivalent to running the shell command gitk --all --not ORIG_HEAD
. Note that shell commands will be executed from the top-level directory of a repository, which may not necessarily be the current directory.
我的 .gitconfig br = checkout -b
中有以下别名,因此 git br feature
创建并检出一个名为 feature
不过,我真正想要的行为是 git br feature
创建一个分支 wheresrhys/feature
。
如何使用连接在 git 别名中创建所需的名称?
如果您 运行 git 来自类 Unix shell,常见的技巧是在您的别名定义中使用 shell 函数。在您的 .gitconfig
中添加以下内容即可。
[alias]
br = "!f() { git checkout -b wheresrhys/; }; f"
关于感叹号或感叹号,git config
文档注释
If the alias expansion is prefixed with an exclamation point, it will be treated as a shell command. For example, defining
alias.new = !gitk --all --not ORIG_HEAD
, the invocationgit new
is equivalent to running the shell commandgitk --all --not ORIG_HEAD
. Note that shell commands will be executed from the top-level directory of a repository, which may not necessarily be the current directory.