Git branch - simple command

先在桌面创建一个目录myGit2,在该目录下初始化一个git仓库:
Git branch - simple command
创建一个新的分支命令:git branch branchName
删除一个新的分支命令:git branch -d branchName(该分支与master完全一致的前提)
Git branch - simple command
如果branch与master不一致,若要删除branch,用git branch -D branchName:
Git branch - simple command
创建分支并且切换到当前分支上面可用一个命令:git checkout -b branchName
此命令可以代替两个命令:git branch branchName 和 git checkout branchName
Git branch - simple command
另外在两个branch 之间切换可以用git checkout -,从上面可以看到。
在branch01中添加一个newBranch01.txt文件,并加入几行文本,并提交:
Git branch - simple command
可以编辑一下newBranch01.txt,添加两行hello branch02/hello branch03,使用命令:vi newBranch01.txt
Git branch - simple command
编辑完按ESC退出,shift+: 输入命令wq,结束编辑并保存退出,若想再次想再后面追加编辑,shift+g跳到最后一行,shift+a跳到行尾。
可以看到master分支下面没有newBranch01.txt,而处在master分支下时,是不能直接删除掉branch01分支,使用git branch -d branchName。这个时候也可以用git merge branch01的方式让master分支与branch01保持一致,然后就可以直接使用前面的命令将branch01删除:
Git branch - simple command