Make an existing Git branch track a remote branch?

前端 未结 22 2952
执念已碎
执念已碎 2020-11-21 07:16

I know how to make a new branch that tracks remote branches, but how do I make an existing branch track a remote branch?

I know I can just edit the

22条回答
  •  抹茶落季
    2020-11-21 07:56

    This isn't a direct answer to this question, but I wanted to leave a note here for anyone who may be having the same issue as me when trying to configure an upstream branch.

    Be wary of push.default.

    With older git versions, the default was matching, which would cause very undesirable behaviour if you have, for example:

    Local branch "master" tracking to origin/master

    Remote branch "upstream" tracking to upstream/master

    If you tried to "git push" when on the "upstream" branch, with push.default matching git would automatically try to merge the local branch "master" into "upstream/master", causing a whole lot of chaos.

    This gives more sane behaviour:

    git config --global push.default upstream

提交回复
热议问题