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 。
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 reset --hard e3333333333333
強制提交
git push -f origin branch
-------------------------------------------
詳細學習教程可參考