創建分支:
git branch branch_name
切換分支:
git checkout branch_name
創建並切換分支
git checkout -b branch_name
創建遠程分支到本地:
git checkout -b branch_name origin/branch_name
查看當前分支:
git branch
獲取所有分支:
git fetch
合併某分支到當前分支:
git merge branch_name
禁用Fast forward(快速合併), 普通模式合併:
git merge --no-ff -m "merge with no-ff" branch_name
這裏會在合併的時候自動生成一個新的commit
刪除分支:
git branch -d branch_name
強制刪除分支(用於爲合併就刪除時):
git branch -D branch_name
查看分支合併圖:
git log --graph
保存分支工作現場:
git stash
查看保存列表:
git stash list
恢復保存狀態:
git stash apply
git stash apply stash@{x}
刪除保存狀態:
git stash drop
git stash drop stash@{x}
恢復並刪除保存狀態:
git stash pop
推送分支到遠程倉庫:
git push origin branch_name
建立本地分支與遠程分支的關聯:
git branch --set-upstream branch-name origin/branch-name