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

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

    Prior to the introduction of git push -u, there was no git push option to obtain what you desire. You had to add new configuration statements.

    If you create a new branch using:

    $ git checkout -b branchB
    $ git push origin branchB:branchB
    

    You can use the git config command to avoid editing directly the .git/config file.

    $ git config branch.branchB.remote origin
    $ git config branch.branchB.merge refs/heads/branchB
    

    Or you can edit manually the .git/config file to had tracking information to this branch.

    [branch "branchB"]
        remote = origin
        merge = refs/heads/branchB
    

提交回复
热议问题