您的位置:首页 > 其它

Git 常用操作(九) git checkout 与分支切换

perfectnihil 2017-10-13 11:05 29 查看
Section1 切换分支

superDy@DESKTOP-85E2I07 MINGW64 /c/test/gittest/GitTest (master)

$ git branch

* master

  test3

superDy@DESKTOP-85E2I07 MINGW64 /c/test/gittest/GitTest (master)
$ git checkout test3

Switched to branch 'test3'

superDy@DESKTOP-85E2I07 MINGW64 /c/test/gittest/GitTest (test3)
$ git checkout master

Switched to branch 'master'

Your branch is up-to-date with 'origin/master'.

superDy@DESKTOP-85E2I07 MINGW64 /c/test/gittest/GitTest (master)

$

Section2 新建分支

superDy@DESKTOP-85E2I07 MINGW64 /c/test/gittest/GitTest (test3)
$ git branch anewtestbranch

superDy@DESKTOP-85E2I07 MINGW64 /c/test/gittest/GitTest (test3)

$ git branch

  anewtestbranch

  master

* test3

git branch xxx  即为创建一个新分支

这时候执行checkout

superDy@DESKTOP-85E2I07 MINGW64 /c/test/gittest/GitTest (test3)
$ git checkout anewtestbranch

Switched to branch 'anewtestbranch'

superDy@DESKTOP-85E2I07 MINGW64 /c/test/gittest/GitTest (anewtestbranch)

$ git branch

* anewtestbranch

  master

  test3

则切换到新的分支了

Section3  简便的方式

其实创建新分支并切换到新分支还有一步到位的方式

superDy@DESKTOP-85E2I07 MINGW64 /c/test/gittest/GitTest (test3)
$ git checkout -b thenewbranch

Switched to a new branch 'thenewbranch'

superDy@DESKTOP-85E2I07 MINGW64 /c/test/gittest/GitTest (thenewbranch)

$ git branch

  master

  test3

* thenewbranch

这个时候创建新分支和切换到新分支就一步到位的完成了
标签:  git