git 更改分支

编程笔记 | Switch Branch using git checkout

Posted by 陈陈 on December 7, 2020

github 同步当地仓库见上一篇总结 chensong212.github.io/2020/11/21/summary/

This summary explain how to switch branch using git checkout, and deal with a remote branch.

1. Enter the main directory, check the branches

$ git branch

3. Build a new branch

If the destination branch does not exist, you have to append the “-b” option, otherwise you won’t be able to switch to that branch.

$ git checkout -b “name of new_branch”

3. Switch the branch

$ git checkout “name of branch”

4. Git Checkout a Remote Branch

In order to checkout a remote branch you have to first fetch the contents of the branch.

$ git fetch –all

5. Commit the changes

$ git commit -m “some description of the modification” “name of file”

6. Set the upstream origin

$ git push –set-upstream origin “name of branch”

7. Push to the remote branch

$ git push