1、創(chuàng)建本地分支 local_branch
git branch local_branch
2、創(chuàng)建本地分支local_branch 并切換到local_branch分支
git checkout -b local_branch
3、切換到分支local_branch
git checkout local_branch
4、推送本地分支local_branch到遠(yuǎn)程分支 remote_branch并建立關(guān)聯(lián)關(guān)系
// a.遠(yuǎn)程已有remote_branch分支并且已經(jīng)關(guān)聯(lián)本地分支local_branch且本地已經(jīng)切換到local_branch
git push
// b.遠(yuǎn)程已有remote_branch分支但未關(guān)聯(lián)本地分支local_branch且本地已經(jīng)切換到local_branch
git push -u origin/remote_branch
// c.遠(yuǎn)程沒有有remote_branch分支并,本地已經(jīng)切換到local_branch
git push origin local_branch:remote_branch
5、刪除本地分支local_branch
git branch -d local_branch
6、查看本地分支
git branch
7、查看遠(yuǎn)程和本地分支
git branch -a
8、已經(jīng)推送到遠(yuǎn)程倉庫的版本如何進(jìn)行回退
// 先進(jìn)行本地的版本回退
git reset --hard commit_id
// git reset 后, 本地版本回退了, 但無法直接 push 到遠(yuǎn)程倉庫(因?yàn)檫h(yuǎn)程倉庫版本更加新) git push -f 覆蓋推送即可
git push -f
// 回退前,用git log可以查看提交歷史,以確定要回退的commit_id。
commit_id
// 如果后悔回退了,用git reflog查看命令歷史,以便確定要回到的版本的commit_id。
git reflo
9、新建本地分支并與遠(yuǎn)程分支關(guān)聯(lián)
git checkout -b shangcheng origin/shangcheng
// 如果失敗,執(zhí)行以下命令同步遠(yuǎn)端和本地分支記錄
git fetch origin
10、將本地新建項(xiàng)目與遠(yuǎn)程新建項(xiàng)目關(guān)聯(lián)
// 將本地新建項(xiàng)目與遠(yuǎn)程新建項(xiàng)目關(guān)聯(lián)
git remote add origin 遠(yuǎn)程項(xiàng)目地址
// 推送本地項(xiàng)目到遠(yuǎn)程項(xiàng)目 第一次要加 -u
git push -u origin master