1、创建本地分支 local_branch
git branch local_branch
2、创建本地分支local_branch 并切换到local_branch分支
git checkout -b local_branch
3、切换到分支local_branch
git checkout local_branch
4、推送本地分支local_branch到远程分支 remote_branch并建立关联关系
// a.远程已有remote_branch分支并且已经关联本地分支local_branch且本地已经切换到local_branch
git push
// b.远程已有remote_branch分支但未关联本地分支local_branch且本地已经切换到local_branch
git push -u origin/remote_branch
// c.远程没有有remote_branch分支并,本地已经切换到local_branch
git push origin local_branch:remote_branch
5、删除本地分支local_branch
git branch -d local_branch
6、查看本地分支
git branch
7、查看远程和本地分支
git branch -a
8、已经推送到远程仓库的版本如何进行回退
// 先进行本地的版本回退
git reset --hard commit_id
// git reset 后, 本地版本回退了, 但无法直接 push 到远程仓库(因为远程仓库版本更加新) git push -f 覆盖推送即可
git push -f
// 回退前,用git log可以查看提交历史,以确定要回退的commit_id。
commit_id
// 如果后悔回退了,用git reflog查看命令历史,以便确定要回到的版本的commit_id。
git reflo
9、新建本地分支并与远程分支关联
git checkout -b shangcheng origin/shangcheng
// 如果失败,执行以下命令同步远端和本地分支记录
git fetch origin
10、将本地新建项目与远程新建项目关联
// 将本地新建项目与远程新建项目关联
git remote add origin 远程项目地址
// 推送本地项目到远程项目 第一次要加 -u
git push -u origin master