Default behavior of “git push” without a branch specified

前端 未结 12 1337
眼角桃花
眼角桃花 2020-11-22 05:32

I use the following command to push to my remote branch:

git push origin sandbox

If I say

git push origin

12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 06:12

    A git push will try and push all local branches to the remote server, this is likely what you do not want. I have a couple of conveniences setup to deal with this:

    Alias "gpull" and "gpush" appropriately:

    In my ~/.bash_profile

    get_git_branch() {
      echo `git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
    }
    alias gpull='git pull origin `get_git_branch`'
    alias gpush='git push origin `get_git_branch`'
    

    Thus, executing "gpush" or "gpull" will push just my "currently on" branch.

提交回复
热议问题