git - 如果我必须在两个地方重复相同的文本,git 别名可以使用参数吗?

标签 git

如果不使用 shell,我可以在 git 别名上使用参数吗?

例如,我的主要远程分支始终称为“上游”,有时 git 会丢失本地分支的引用并说:

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=<remote>/<branch> master

我想要一个别名,例如

[alias]
    reup = branch --set-upstream-to=upstream/$1 $1

这样我就可以输入git reup master

(或者更好的是,将 git 配置为始终假定远程为“上游”?)

最佳答案

不使用外壳?不。但是对于 shell,当然可以:

[alias]
brup = "!f() { git branch --set-upstream-to=${2:-origin}/$1 $1; }; f"

现在,您可以运行 git brup dev 将上游设置为 origin/devgit brup devupstream 将上游设置为 上游/dev

关于git - 如果我必须在两个地方重复相同的文本,git 别名可以使用参数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50297197/

相关文章:

git - 为一个简单的网站选择一个版本控制系统

Git 从其他人所做的远程中删除最后一次提交

git - 在 Windows (WSL) 上的 Ubuntu 上将 Git 与 VS Code 和 Bash 结合使用

git - 提交并自动添加所有未跟踪的文件

git - 使用 git-p4 克隆部分 Perforce 仓库

git - 为什么 git-svn 应该积极搜索旧历史?

r - devtools::install_git 通过 SSH

git - 是否可以动态生成git日志格式?

ios - Git clone 在 MAC OSX 10.12 上接收对象挂起

git 子模块替换不会分离头