1. 查看本地分支
git branch 。命令会列出所有分支,当前分支前面会标一个*号。
2. 查看本地和远程所有分支
git branch -a
3. 切换分支
git checkout xxx 。命令切换到xxx分支。
4. 创建本地分支
git branch local_branch
5. 创建本地分支 并切换
git checkout -b dev 。git checkout命令加上-b参数表示创建并切换到dev
6. 提交代码到本地仓库
git add . 。
git commit -a -m "description" 。把全部更改提交到本地库
7. 合并指定分支xxx到当前分支
git merge xxx 。也就是直接把当前分支指针指向xxx的当前提交。
8. 拉远程分支remote_branch到本地,在本地起名为local_branch,并切换到本地的local_branch分支
git checkout -b local_branch origin/remote_branch 。
方法二:git fetch origin remote_branch:local_branch 获取远程分支,新建本地分支。
git checkout local_branch 切换到新建分支
9. 推送本地分支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
10. 删除本地分支local_branch ,不能在要删除的分支上,先切到其他分支,再删除
git branch -d local_branch
11. 删除远程分支remote_branch
git push origin :remote_branch
git branch -m | -M oldbranch newbranch 重命名分支,如果newbranch名字分支已经存在,则需要使用-M强制重命名,否则,使用-m进行重命名。
git branch -d | -D branchname 删除branchname分支
git branch -d -r branchname 删除远程branchname分支
12.查看远程分支是否已经删除git branch -p
通过git branch -a 仍然可以看到该分支,
那么通过git remote show origin命令查看
12.查看版本号,回滚到指定的版本
git log --pretty=oneline
git reset --hard e3333333333333
强制提交
git push -f origin branch
-------------------------------------------
详细学习教程可参考