Why do I need to do `--set-upstream` all the time?

后端 未结 21 2046
南方客
南方客 2020-11-22 09:15

I create a new branch in Git:

git branch my_branch

Push it:

git push origin my_branch

Now say someone mad

相关标签:
21条回答
  • 2020-11-22 09:24
    git branch --set-upstream-to=origin/master<branch_name>
    
    0 讨论(0)
  • 2020-11-22 09:25

    You can make this happen with less typing. First, change the way your push works:

    git config --global push.default current
    

    This will infer the origin my_branch part, thus you can do:

    git push -u
    

    Which will both create the remote branch with the same name and track it.

    0 讨论(0)
  • 2020-11-22 09:28

    You can also do git push -u origin $(current_branch)

    0 讨论(0)
  • 2020-11-22 09:28

    All i wanted was doing something like this:

    git checkout -b my-branch
    git commit -a -m "my commit"
    git push
    

    Since i didn't found a better solution, i've just created an bash alias on ~/.bashrc:

    alias push="git push -u origin HEAD"
    

    now just doing a push command does the job (you can add this alias on ~/.gitconfig too with another name, such as pushup)

    0 讨论(0)
  • 2020-11-22 09:30

    We use phabricator and don't push using git. I had to create bash alias which works on Linux/mac

    vim ~/.bash_aliases
    
    new_branch() {
        git checkout -b "$1"
        git branch --set-upstream-to=origin/master "$1"
    }
    

    save

    source ~/.bash_aliases
    new_branch test #instead of git checkout -b test
    git pull
    
    0 讨论(0)
  • 2020-11-22 09:32

    I sort of re-discovered legit because of this issue (OS X only). Now all I use when branching are these two commands:

    legit publish [<branch>] Publishes specified branch to the remote. (alias: pub)

    legit unpublish <branch> Removes specified branch from the remote. (alias: unp)

    SublimeGit comes with legit support by default, which makes whole branching routine as easy as pressing Ctrl-b.

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