版權申明】非商業目的z註明出處可自由轉載
博文地址:https://blog.csdn.net/ShuSheng0007/article/details/89642945
出自:shusheng007
相關文章
實際項目中如何使用Git做分支管理
文章目錄
1 從本地分支A創建分支B 並切換到B
在任意分支上執行
git checkout -b B A
如果在A 分支上執行,那麼上面語句的A可以省略
2從遠程分支A創建分支B 並切換到B
在任意分支上執行
git checkout -b B origin/A
3 從遠端分支刷新本地分支commit 記錄
git fetch <遠程主機名>
git fetch
上面命令將某個遠程主機的更新,全部刷新回本地。
git fetch origin master
將遠程origin主機的master分支commit 刷新到本地。
默認情況下,刷新回來的數據在.git/FETCH_HEAD
中
4 刪除本地分支A
在非A的分支上執行
git branch -d A
5 強行刪除本地分支A
在非A的分支上執行
git branch -D A
6 刪除遠程分支A
在任意分支上執行
git push origin --delete A
7 合併分支A 到分支 B上
在分支B分支上執行
$ git merge --no-ff A
上面代碼的–no-ff 表示不用快速合併
8 上傳代碼到github
1.git remote add origin 倉庫地址
2.git pull origin master 同步遠程倉庫
3.add . commit …
4.git push -u origin master
9 電腦修改密碼後,輸入密碼的提示不出現了,直接報 Authentication failed for
git config --system --unset credential.helper
或者
git config --global --unset credential.helper
10 結束一個git命令
輸入Q鍵即可
11 創建遠端分支
只要將本地分支push到遠端就可以了
$ git push origin test:origin/test
上面的命令用本地分支test在遠端創建了一個test分支
12 將本地分支與遠端分支關聯,如果遠端分支不存在則創建並關聯
git push --set-upstream origin branch_name
上面的命令將當前本地分支與名爲branch_name的遠端分支關聯
13 取消本地分支與遠端分支的關聯關係
git push --unset-upstream origin branch_name
上面的命令將當前本地分支與名爲branch_name的遠端分支取消關聯
14 從遠端創建本地同名分支並關聯
git checkout --track origin/branch_name
從遠端branch_name分支創建本地同名分支並關聯
15 從遠端創建本地自定義名稱分支並關聯
git checkout -b new_branch_name origin/branch_name
上面的命令以branch_name的遠端分支創建本地分支new_branch_name
16 查看遠端分支情況
git branch -r
17 從遠端克隆某一個分支
git clone -b [remote repository address]
$ git clone https://github.com/shusheng007/learngit.git
上面的命令克隆我GitHub上的默認主分支:master
$ git clone -b newbranch https://github.com/shusheng007/learngit.git
上面的命令克隆我GitHub上的名爲newbranch 的一個分支