Git alias on current branch

后端 未结 4 562
没有蜡笔的小新
没有蜡笔的小新 2020-12-24 12:00

I\'d like to improve my current aliases, most of them work over a branch. Is there a way to refer to the current branch in a git alias so I don\'t need to pass it each time?

相关标签:
4条回答
  • 2020-12-24 12:42
    [alias]
      po = "!git push --set-upstream origin \"$(git rev-parse --abbrev-ref HEAD)\""
    
    0 讨论(0)
  • 2020-12-24 12:46

    This answer will be valid starting from Git 2.0, where the default push behaviour will be simple

    Unless push.default setting is set to matching, git push without specifying argument will always push the current branch, so in this case you don't need to specify it.

    0 讨论(0)
  • 2020-12-24 12:50

    It's not 100% clear from your question which of these two aliases you require.

    This will push the currently checked out branch:

    git config alias.po !f() { export tmp_branch=`git branch | grep '* ' | tr -d '* '` && git push origin $tmp_branch; unset $tmp_branch; }; f
    

    This will push a given branch name (git po branchName):

    git config alias.po !f() { git push origin $1; }; f
    
    0 讨论(0)
  • 2020-12-24 13:01

    git symbolic-ref --short HEAD prints the current branch, so you can define a simple shell alias:

    alias gpo='git push origin "$(git symbolic-ref --short HEAD)"'
    
    0 讨论(0)
提交回复
热议问题