How do I push a new local branch to a remote Git repository and track it too?

后端 未结 15 1584
逝去的感伤
逝去的感伤 2020-11-22 09:17

I want to be able to do the following:

  1. Create a local branch based on some other (remote or local) branch (via git branch or git checkout

15条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 10:05

    I made an alias so that whenever I create a new branch, it will push and track the remote branch accordingly. I put following chunk into the .bash_profile file:

    # Create a new branch, push to origin and track that remote branch
    publishBranch() {
      git checkout -b $1
      git push -u origin $1
    }
    alias gcb=publishBranch
    

    Usage: just type gcb thuy/do-sth-kool with thuy/do-sth-kool is my new branch name.

提交回复
热议问题