How to create a local branch from an existing remote branch?

后端 未结 5 2012
半阙折子戏
半阙折子戏 2021-01-31 08:42

I want to create a branch from an existing remote branch (let\'s say remote-A) and then commit the changes to the repository.

I have used the below commands to create a

5条回答
  •  暖寄归人
    2021-01-31 09:27

    Old post, still I'd like to add what I do.

    1. git remote add  
    2. git fetch 
    3. git checkout -b  /
    

    This series of commands will

    1. create a new remote,
    2. fetch it into your local so your local git knows about its branches and all,
    3. create a new branch from the remote branch and checkout to that.

    Now if you want to publish this new local branch to your remote and set the upstream url also

    git push origin +

    Also, if only taking in remote changes was your requirement and remote already exists in your local, you could have done, instead of step 2 and 3,

    git pull --rebase  
    

    and then opted for git mergetool (needs configurations separately) in case of any conflicts, and follow console instructions from git.

提交回复
热议问题