git alias for HEAD:refs/for/master

前端 未结 8 2214
予麋鹿
予麋鹿 2020-12-02 09:18

I am configuring Gerrit and I would like to avoid writing:

git push gerrit HEAD:refs/for/master

I would like to write:

相关标签:
8条回答
  • 2020-12-02 09:37

    You might also be interested in git-review, which not only eliminates the push by simply providing for:

    git review
    

    ... but also lets you do things like:

    git review branchname
    

    Checkout the Usage section on the link above for more.

    0 讨论(0)
  • 2020-12-02 09:42

    What you're best off doing is a Git scriptlet in your alias. Something like this works based on the 'upstream' branch, although I'd like to clean this up a little bit still:

    ~/.gitconfig

    [alias]
      pub = "!f() { git push -u ${1:-origin} HEAD:`git config branch.$(git name-rev --name-only HEAD).merge | sed -e 's@refs/heads/@refs/for/@'`; }; f"
    

    This way, you can simply type:

    git pub
    

    and it's just like you typed:

    git push -u origin HEAD:refs/for/master
    

    or

    git push -u origin HEAD:refs/for/myremote-branch
    

    The only requirement for this is that it is only compatible with the Git Bash shell on Windows, or one of the many Linux shells.

    0 讨论(0)
提交回复
热议问题