git 建立本地分支、提交到遠端分支
阿新 • • 發佈:2019-01-09
1、檢視本地分支:
$ git branch
master
* mutilrecall
檢視遠端分支:
$ git branch -a
master
* mutilrecall
remotes/origin/master
remotes/origin/mutilrecall
注:其中,remotes開頭的代表是遠端分支。
2、建立本地分支,並切換到分支:
$ git branch test [email protected] MINGW64 /e/workspace_ttengine/ttengine (mutilrecall) $ git checkout test Switched to branch 'test'
3、本地分支關聯遠端分支:
在本地test分支上修改了程式碼後,需要提交到遠端,這時就需要關聯遠端的某個遠端分支,操作如下:
1)本地提交:
git gui
2)push到遠端
$ git push origin test:test Counting objects: 15, done. Delta compression using up to 4 threads. Compressing objects: 100% (9/9), done. Writing objects: 100% (15/15), 927 bytes | 0 bytes/s, done. Total 15 (delta 7), reused 7 (delta 0) remote: remote: Create merge request for test: remote: http://gitlab.avc.domain/ttengine/ttengine/merge_requests/new?merge_request%5Bsource_branch%5D=test remote: To http://gitlab.avc.domain/ttengine/ttengine.git * [new branch] test -> test
注:第一次無法pull,只能push
注:如果不寫遠端分支名稱,則預設和本地分支同名,這時命令為:$ git push origin test
3)從遠端pull:
$ git pull origin test:test
Already up-to-date.
注:如果不寫本地分支名稱,則預設和遠端分支同名,這時命令為:$ git pull origin test:
3、從遠端分支上下程式碼:
$ git clone -b mutilrecall http://gitlab.avc.domain/ttengine/ttengine.git
clone遠端倉庫到制定目錄:
git clone xxx.git "指定目錄"
說明:關於git 的pull、push、fetch、remote等命令見下篇文章。