Git Branch(分支)

Git Branch(分支)

1. 查看分支

git branch

2. 創建分支

git branch <branch-name>

3. 切換分支

git checkout <branch-name>

4. 創建 + 切換分支

git checkout -b <branch-name>

5. 合併某分支到 當前分支上

// fast forward 合併模式
git merge <branch-name>
// 普通合併模式
git merge --no-ff -m 'some comments' dev

6. 刪除分支

git branch -d <branch-name>
// 強行刪除一個沒有被合併過的分支
git branch -D <branch-name>

7. 查看合併分支情況

git log --graph --pretty=oneline --abbrev-commit

8. stash

// 當前工作副本臨時保存
git stash
// 所有 stash 的工作副本
git stash list
// 恢復工作副本(並不刪除)
git stash apply stash@{0}
// 刪除工作副本
git stash grop stash@{0}
// 恢復最近一次的工作副本, 並且刪除該副本
git stash pop

9. 與遠程服務器

// 查看遠程服務器信息
git remote -v
// 將本地分支推送到遠程服務器(本地不推送到遠程服務器,別人看不到)
// (如果失敗可以先 git pull 從服務器上拉取新的提交)
git push origin local-branch:remote-branch
// 創建本地和遠程對應的分支
// (兩者名稱最好一直)
git checkout -b <branch-name> origin/<branch-name>
// 建立本地分支與遠程分支的關聯
git branch --set-upstream <branch-name> origin/<branch-name>
// 從遠程分支抓取
git pull
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章