git命令-切换分支

来源:互联网 发布:诺瓦刷屏软件 编辑:程序博客网 时间:2024/05/17 06:02

Git一般有很多分支,我们clone到本地的时候一般都是master分支,那么如何切换到其他分支呢?主要命令如下:

1. 查看远程分支

$ git branch -a 
我在mxnet根目录下运行以上命令:

~/mxnet$ git branch -a* master  remotes/origin/HEAD -> origin/master  remotes/origin/master  remotes/origin/nnvm  remotes/origin/piiswrong-patch-1  remotes/origin/v0.9rc1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

可以看到,我们现在在master分支下

2. 查看本地分支

~/mxnet$ git branch* master
  • 1
  • 2
  • 1
  • 2

3. 切换分支

$ git checkout -b v0.9rc1 origin/v0.9rc1Branch v0.9rc1 set up to track remote branch v0.9rc1 from origin.Switched to a new branch 'v0.9rc1'#已经切换到v0.9rc1分支了$ git branch  master* v0.9rc1#切换回master分支$ git checkout masterSwitched to branch 'master'Your branch is up-to-date with 'origin/master'.
原创粉丝点击