首先我们应该了解一个知识点:即使没有Github,我们依然可以使用Git工具在本地仓库中管理我们的项目,可以完成创建分支、合并分支等功能。
所以这里我会从以下两个方面进行阐述:使用Git工具在本地创建分支、将本地的分支上传到远程仓库中
一、使用Git工具在本地创建分支
第一步:在本地创建一个仓库,并新建好一个文件(如果这一点不会做的话,可以看我之前的一篇博客 Git与Github的使用总结 – day 01)
第二步:将本地仓库中的这个文件进行提交。

完成提交之后,我们就可以使用命令 git branch
来查看Git工具为我们自动创建好的默认分支master

- 第三步:在本地新建分支。我们可以使用
git branch branchName
来创建我们的分支。这里的branchName
是我们新建分支的名字。

新建好分支之后,我们可以使用 git branch
命令来查看当前项目中的所有分支以及我们当前所在的分支。

新建好分支之后,我们可以使用 git checkout branchName
命令切换到我们想要去的分支中。

或者在新建分支的时候,我们可以使用 git checkout -b branchName
命令。这样我们在新建好分支之后立刻切换到该分支下。

本地分支管理的其他操作命令:
1. 删除分支命令:git branch -d branchName

这里需要注意一下,如果我们当前正在test分支下,那么是不可以使用该命令删除test分支的。
2. 分支合并命令: git merge branchName
一般情况下我们都是将其他分支合并到 master 分支中,所以我们使用这条命令之前,要先切换到 master 分支中。

如果我们没有完成分支合并,并且我们在master分支中提交了master.txt文件,在fengzhen分支中提交了fengzhen.txt文件。这个时候我们在切换分支的时候,在本地文件夹中看到的内容是不一样的。
切换到master分支后,我们在本地文件夹中看到的文件

切换到fengzhen分支后,我们在本地文件夹中看到的文件

二、将本地的分支上传到远程仓库中
- 第一步:使用命令
git remote add origin
远程仓库地址 关联本地仓库和远程仓库

- 第二步:使用命令
git pull
拉去远程仓库中的分支

我们可以使用 git branch -a
查看本地和远程中的仓库。这里注意一下,下图白框中的origin,后面会用到。

- 第三步:使用
git push origin localBranchName
命令将本地仓库中的分支上传到远程仓库中。命令中的origin
即是上图中的origin(一般情况下都是origin);命令中的localBranchName
是我们本地分支的名称。

这个时候来到我们的Github网站中,就可以看到我们成功上传的 fengzhen 分支

????????????