Getting existing git branches to track remote branches

前端 未结 7 952
一整个雨季
一整个雨季 2021-01-29 21:43

My usual workflow when working with git, is something like this:

  1. create a local repository
  2. do some work in that repository, add/change files etc.
7条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-29 21:51

    Use the set-upstream arg:

    git branch --set-upstream local-branch-name origin/remote-branch-name
    

    Running the above command updates your .git/config file correctly and even verifies with this output:

    "Branch local-branch-name set up to track remote branch remote-branch-name from origin."

    EDIT: As martijn said: "In version Git v1.8.0, --set-upstream is deprecated. Use --set-upstream-to instead."

    git branch --set-upstream-to local-branch-name origin/remote-branch-name
    

    See this for more information.

提交回复
热议问题