简体   繁体   中英

Creating Git Rebase Alias

I have this git command that I use a lot as an zsh function.

git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD)

What I want to achive is create an alias and be able to call it as git upstream rather than calling just $ upstream as an zsh function. The closest I did get was this:

[alias]
    upstream = "!fn() { git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD) }; fn"

However, my guess is, it does fail at $(...) due to some parsing error. The error it shows me is this:

> git upstream
fn() { git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD) }; fn: -c: line 1: syntax error: unexpected end of file

Is what I am trying to do through aliases possible? If not, can you direct me to any kind of a source to create git upstream command?

In your local bin directory for example ~/bin Create a git-upstream file:

#!/bin/sh
git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD)

Then make it executable

chmod u+x git-upstream

Now you can call git upstream

Turns out I was very close but just missed a semicolon! ♂️

[alias]
  upstream = "!f() { git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD); }; f"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM