- 克隆指定分支
```bash
git clone -b 分支名
```
- 撤銷工作區修改
```bash
git checkout -- 文件名
```
- 拉取遠程指定分支
```bash
git checkout -b 本地分支名x origin/遠程分支名x
# 使用該方式會在本地新建分支x,并自動切換到該本地分支x。
# 采用此種方法建立的本地分支會和遠程分支建立映射關系。
```
```bash
git fetch origin 遠程分支名x:本地分支名x
# 使用該方式會在本地新建分支x,但是不會自動切換到該本地分支x,需要手動checkout。
# 采用此種方法建立的本地分支不會和遠程分支建立映射關系。
```
- 強制推送代碼
```bash
git push -u origin 分支名 -f
```
- 查看commit提交記錄
```bash
git reflog
```
- 返回到某個commit
```bash
git reset --hard commit_id
```
- 合并分支
```bash
# 當前分支為 bugfix_001 合并master分支
git merge --no-ff --no-edit origin/master
```
- 放棄本地所有修改
```bash
git checkout .
```
- 本地分支關聯遠程分支
```bash
git branch --set-upstream-to origin/test1 test1
```