1惯退、初始化倉(cāng)庫(kù)
git init
2披粟、 添加文件到本地倉(cāng)庫(kù)
git add .(文件name)
3咒锻、添加文件描述信息
git commit -m "first commit"
4、鏈接遠(yuǎn)程倉(cāng)庫(kù)守屉,創(chuàng)建主分支
git remote add origin + 遠(yuǎn)程倉(cāng)庫(kù)地址
5惑艇、把本地倉(cāng)庫(kù)的變化連接到遠(yuǎn)程倉(cāng)庫(kù)主分支
git pull origin master
這一步如果報(bào)錯(cuò):refusing to merge unrelated histories
(1) 執(zhí)行:
git pull origin master --allow-unrelated-histories
或 git pull --allow-unrelated-histories
如果報(bào)錯(cuò):
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch>
說(shuō)明本地分支和遠(yuǎn)程分支沒(méi)有建立聯(lián)系,執(zhí)行下面命令來(lái)建立聯(lián)系
git branch --set-upstream-to=origin/遠(yuǎn)程分支的名字 本地分支的名字
(2) 如果繼續(xù)報(bào)錯(cuò):
error: failed to push some refs to 'git@github.com:CNCFOX/NDKLearn.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
通過(guò)git status
查看提交過(guò)程:
此時(shí)Git處于mergeing的狀態(tài)拇泛,在VScode中會(huì)標(biāo)出沖突的部分滨巴,選擇接受現(xiàn)有更改或者其他選擇。完成后打開(kāi)VScode中左邊的git工具欄俺叭,接受已經(jīng)做出的更改恭取。
(3) 這些操作完成之后,重新執(zhí)行git add .
(4) 然后執(zhí)行git commit -s
(5) 再執(zhí)行git pull origin master
6熄守、將代碼push到遠(yuǎn)程的倉(cāng)庫(kù)中
git push origin master
注:
如果在執(zhí)行g(shù)it clone時(shí)只clone了部分文件說(shuō)明沒(méi)有指定具體的分支
1.git clone 不指定分支
git clone http://10.1.1.11/service/sz-service.git
2.git clone 指定分支
git clone -b master http://10.1.1.11/service/sz-service.git
命令中:
多了一個(gè)-b master蜈垮,這個(gè)master就是分支,http://10.1.1.11/service/sz-service.git為源碼的倉(cāng)庫(kù)地址