How to cleanly get/copy a remote git branch to local repository

前端 未结 2 1726
广开言路
广开言路 2021-01-30 03:45

I want an exact \"copy\" of a remote branch \"copied\" to a specific local branch.

Say, for example, a team member has created an experimental feature, which he has che

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 04:27

    If you don't care about merging:

    git reset --hard /
    

    This will exactly do what you want: no merging, no rebasing, simply put the local branch to exactly the same state as the remote is.

    In your case however, you don't need that. You want to create a new local branch that has the same state as the remote, so specify the remote branch when creating the local one with git checkout:

    git checkout -b  /
    

    If you want to use the same name locally, you can shorten that to:

    git checkout 
    

    You would use git reset --hard if you already have a local branch (for example with some changes in it), discard any modifications that you made and instead take the exact version of the remote branch.

    To be sure that you have the latest state of the remote branch, use git fetch before either checking out or resetting.

提交回复
热议问题