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

后端 未结 15 1555
逝去的感伤
逝去的感伤 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:03

    I simply do

    git push -u origin localBranch:remoteBranchToBeCreated
    

    over an already cloned project.

    Git creates a new branch named remoteBranchToBeCreated under my commits I did in localBranch.

    Edit: this changes your current local branch's (possibly named localBranch) upstream to origin/remoteBranchToBeCreated. To fix that, simply type:

    git branch --set-upstream-to=origin/localBranch
    

    or

    git branch -u origin/localBranch
    

    So your current local branch now tracks origin/localBranch back.

提交回复
热议问题