需求
在開發(fā)項(xiàng)目中黑界,需要在基礎(chǔ)框架代碼上進(jìn)行開發(fā)仍源,但又想能及時(shí)更新基礎(chǔ)框架代碼的新功能童本,所以就有fork 項(xiàng)目, update 遠(yuǎn)程倉(cāng)庫(kù)代碼的操作需求哗总。
操作過(guò)程
fork項(xiàng)目
在操作項(xiàng)目時(shí)几颜,先f(wàn)ork一個(gè)基礎(chǔ)項(xiàng)目,在以inmansoft-backend項(xiàng)目為例
更新源項(xiàng)目代碼
當(dāng)源項(xiàng)目代碼有更新時(shí)讯屈,我們可以通過(guò)remote的方式去獲取更新
更新步驟
主要的操作命令:
- 查看目前倉(cāng)庫(kù)可以遠(yuǎn)程更新的信息
git remote -v - 配置一個(gè)遠(yuǎn)程更新鏈接蛋哭,要擁有g(shù)it倉(cāng)庫(kù)訪問(wèn)權(quán)限的
git remote add upstream git@github.com:xxx/xxx.git - 拉取遠(yuǎn)程倉(cāng)庫(kù)的代碼
git fetch upstream - 合并遠(yuǎn)程倉(cāng)庫(kù)的代碼
git merge upstream/master - 把遠(yuǎn)程倉(cāng)庫(kù)的代碼作為新源提交到自己的服務(wù)器倉(cāng)庫(kù)中
git push
操作實(shí)例
- 查看目前倉(cāng)庫(kù)可以遠(yuǎn)程更新的信息
$ git remote -v
origin http://username:password@htwy:8088/jenkins/inmansoft-backend.git (fetch)
origin http://username:password@htwy:8088/jenkins/inmansoft-backend.git (push)
- 配置一個(gè)遠(yuǎn)程更新鏈接,要擁有g(shù)it倉(cāng)庫(kù)訪問(wèn)權(quán)限的
$ git remote add fetch-stream http://username:password@htyw:8088/backend/inmansoft-backend.git
$ git remote -v
fetch-stream http://username:password@htyw:8088/backend/inmansoft-backend.git (fetch)
fetch-stream http://username:password@htyw:8088/backend/inmansoft-backend.git (push)
origin http://username:password@htwy:8088/jenkins/inmansoft-backend.git (fetch)
origin http://username:password@htwy:8088/jenkins/inmansoft-backend.git (push)
- 拉取遠(yuǎn)程倉(cāng)庫(kù)的代碼
$ git fetch fetch-stream
remote: Counting objects: 12, done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 12 (delta 6), reused 0 (delta 0)
Unpacking objects: 100% (12/12), done.
From http://htwy:8088/backend/inmansoft-backend
* [new branch] master -> fetch-stream/master
- 合并遠(yuǎn)程倉(cāng)庫(kù)的代碼
$ git merge fetch-stream/master
Updating 0386ba6..7778790
Fast-forward
src/main/resources/application.yml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
- 把遠(yuǎn)程倉(cāng)庫(kù)的代碼作為新源提交到自己的服務(wù)器倉(cāng)庫(kù)中
$ git push
Enumerating objects: 17, done.
Counting objects: 100% (17/17), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (12/12), done.
Writing objects: 100% (12/12), 1.09 KiB | 223.00 KiB/s, done.
Total 12 (delta 6), reused 0 (delta 0)
To http://htwy:8088/jenkins/inmansoft-backend.git
0386ba6..7778790 master -> master
圖例
fork項(xiàng)目
原始項(xiàng)目 backend/inmansoft-backend
image.png
fork出來(lái)項(xiàng)目 jenkins/inmansoft-backend
image.png