git 在本地建立新分支,並且推送到遠端分支上

2021-07-24 16:00:21 字數 1967 閱讀 6612

git常用命令

一、 建立分支:branchname代表新分支名,otherbranchname遠端分支名

1、根據當前分支建立新分支, branchname代表新分支名

git branch branchname

2、根據其他遠端分支建立新分支

git branch branchname origin/otherbranchname

3、根據其他遠端分支建立新分支並且切換到新建立的分支

git branch –b branchname origin/otherbranchname

二、 提交新建分支

1、提交分支到遠端端

git push origin/branchname

2、是否提交成功: 檢視遠端端所有分支

git branch –r

3、檢視本地分支

git branch

4、檢視本地分支和遠端分支

git branch –a

三、 刪除分支:注意不要在準備刪除的分支上操作

1、  刪除本地分支,僅限沒有提交到遠端的分支

git branch –d origin/branchname

2、  刪除遠端端分支

git branch –r –d origin/otherbranchname

git push origin :otherbranchname  注意:origin 後的空格

3、強制刪除分支把-d 換成 -d

四、切換分支:注意切換分支前需要把所有修改的檔案提交

1、切換分支

git checkout -b  branchname      在本地建立分支並切換到該分支

五、合併分支

1、將開發中的分支(branchname)合併到主分支(otherbranchname)上

首先得重branchname分支切換到otherbranchname分支上

git checkout origin/otherbranchname

合併git merge branchname

如果有衝突可以呼叫gitstatus 檢視

解決衝突,然後呼叫

git add

或git rm

將解決後的檔案暫存。

2、  將開發中的分支(branchname)合併到主分支(otherbranchname)上,不會保留合併日誌

首先得重branchname分支切換到otherbranchname分支上

git checkout origin/otherbranchname

合併git rebase branchname

3、  git merge –no –ff  branchname  

可以儲存你之前的分支歷史。能夠更好的檢視 merge歷史,以及branch狀態。

gitmerge 則不會顯示 feature,只保留單條分支記錄。

六、其他命令

1、將遠端分支資訊獲取到本地

git fetch

2、檢視所有命令

git help

3、撤銷最近一次提交

git reset head^

4、檢視哪些分支合併到當前分支來

git branch –merged

5、檢視哪些分支沒有合併到當前分支

git branch –no –merged

6、檢視所有分支最後一次提交

git branch –v

7、重新命名分支

git branch –m oldbranchnamenewbranchname

8、強制重新命名分支

git branch –m oldbranchnamenewbranchname

9、檢視merge幫助文件

git merge –h  / git merge ——help

10、提交本地分支作為master分支

git push originbranchname:master

git本地建立新分支並推送到遠端倉庫

1,在當前專案目錄,從已有的分支建立新的分支 如從master分支 建立乙個dev分支 git checkout b dev 2,建立完可以檢視一下,分支已經切換到dev git branch dev master 3,提交該分支到遠端倉庫 git push origin dev 4,測試從遠端獲取...

git建立本地分支,推送到遠端

建立本地分支 git branch 分支名 例如 git branch dev,這條命令是基於當前分支建立的本地分支,假設當前分支是master 遠端分支 則是基於master分支建立的本地分支dev。刪除本地分支 必須保證不在刪除的分支上,才能進行刪除 git branch d dev 切換到本地...

git 本地建立分支,推送到遠端

一 建立分支 1.git branch 檢視本地分支 2.git branch a 檢視遠端端的查分支命令 3.建立分支 git checkout b branch1 本地多了分支1 遠端端分支還不變 4.cat test.txt 執行檔案 5.git status 檢視狀態 當前是沒有提交任何東西...