Make an existing Git branch track a remote branch?

前端 未结 22 2946
执念已碎
执念已碎 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:50

    To avoid remembering what you need to do each time you get the message:

    Please specify which branch you want to merge with. See git-pull(1)
    for details.
    .....

    You can use the following script which sets origin as upstream for the current branch you are in.

    In my case I almost never set something else than origin as the default upstream. Also I almost always keep the same branch name for local and remote branch. So the following fits me:

    #!/bin/bash
    # scriptname: git-branch-set-originupstream
    current_branch="$(git branch | grep -oP '(?<=^\* )(.*)$')"
    upstream="origin/$current_branch"
    git branch -u "$upstream"
    

提交回复
热议问题