1.查看所有分支.
git branch -a(查看所有分支包括本地分支和遠(yuǎn)程分支).
git branch -r(查看遠(yuǎn)程分支).
2.本地創(chuàng)建新的分支.
git checkout -b branchname(直接新建一個(gè)分支然后切換至新創(chuàng)建的分支).就是創(chuàng)建加切換分支.
等價(jià)于命令:
git branch branchname+git checkout branchname.
git checkout branchname(切換分支名).
3.將新分支推送至GitHub.
git push origin branchname
4.合并分支操作
1.切換到某一分支進(jìn)行代碼編寫
git checkout branchname
2.提交修改內(nèi)容
git add -a
3.添加說明
git commit -m 'xxx'
4.提交到分支
git push origin branchname
5.切換到主分支
git checkout master
6.合作項(xiàng)目,每次提交前pull一次,本地和遠(yuǎn)程倉庫上代碼合并
git pull origin master
7.合并分支
git merge branchname
8.查看分支中內(nèi)容提交的狀態(tài)
git status
9.提交
git push origin master
10.撤銷到合并前狀態(tài)
git reset --hard HEAD
11.代碼已經(jīng)提交,撤銷的方法是
git reset --hard ORIG_HEAD