[英]git alias to pull --rebase current branch
I am working on a branch called foo
and I want to rebase my branch against origin/foo
. 我正在一个名为
foo
的分支上工作,我希望将我的分支重新设置为origin/foo
。 In modern versions of git I could run 在现代版本的git中,我可以运行
$ git pull --rebase origin foo
That's a lot of typing for a common operation. 这是常见操作的大量打字。 Additionally, because I have an old version of git (see this ), I also need to run a fetch first so that my local graph doesn't seem confusing:
另外,因为我有一个旧版本的git(请参阅此内容 ),我还需要先运行一次获取,以便我的本地图形看起来不会令人困惑:
$ git fetch && git pull --rebase origin foo
How can I write that as a git alias? 我怎么能把它写成git别名?
The command 命令
git symbolic-ref --short HEAD
outputs the short name of the current branch, if any (or HEAD
, if the HEAD is detached). 输出当前分支的短名称(如果有的话)(或
HEAD
,如果分离了HEAD)。 Therefore, you can use it inside a command substitution in your alias definition: 因此,您可以在别名定义中的命令替换中使用它:
git config --global alias.<name> '!git fetch && git pull --rebase origin $(git symbolic-ref --short HEAD)'
where <name>
stands for your alias's name. 其中
<name>
代表别名的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.