Git(1)---git fork 在master上的簡(jiǎn)單嘗試驾霜,暫未涉及分支

1. 使用git fork一個(gè)遠(yuǎn)程A的代碼倉(cāng)庫(kù)的副本到自己的遠(yuǎn)程倉(cāng)庫(kù)

在gitlab或者github上面有fork操作按鈕

2. 拉取自己的遠(yuǎn)程倉(cāng)庫(kù)到自己的本地

$ git clone https://github.com/xxx/yyy.git
Cloning into 'dingding'...
remote: Counting objects: 52, done.
remote: Compressing objects: 100% (47/47), done.
remote: Total 52 (delta 4), reused 52 (delta 4), pack-reused 0
Receiving objects: 100% (52/52), 1.20 MiB | 40.00 KiB/s, done.
Resolving deltas: 100% (4/4), done.

我第一次clone代碼使用的地址是https所以每次push代碼都需要輸入用戶名和密碼驗(yàn)證身份 如下:

$ git push origin master
Username for 'https://github.com': xxx@163.com
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 561 bytes | 0 bytes/s, done.
Total 5 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/xxx/yyy.git
   9623903..ca025de  master -> master

為了方便 現(xiàn)在把拉取遠(yuǎn)程代碼的倉(cāng)庫(kù)地址換成ssh的

$ git remote set-url git@github.com:xxx/yyy.git  // 命令錯(cuò)誤
usage: git remote set-url [--push] <name> <newurl> [<oldurl>]
   or: git remote set-url --add <name> <newurl>
   or: git remote set-url --delete <name> <url>

    --push                manipulate push URLs
    --add                 add URL
    --delete              delete URLs


$  git remote set-url --push origin git@github.com:xxx/yyy.git

3. 修改后提交到自己的遠(yuǎn)程倉(cāng)庫(kù)

添加本地修改到暫存區(qū)

$ git add --all
warning: LF will be replaced by CRLF in .idea/yyy.iml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/modules.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/workspace.xml.
The file will have its original line endings in your working directory.

提交本地修改到本地分支

$ git commit -m "conflict fixed"
[master 26c2de4] conflict fixed
 4 files changed, 283 insertions(+), 1 deletion(-)
 create mode 100644 .idea/datura_lj.iml
 create mode 100644 .idea/modules.xml
 create mode 100644 .idea/workspace.xml

查看代碼狀態(tài)

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working tree clean

沒(méi)有問(wèn)題后,把本地代碼更新到遠(yuǎn)程倉(cāng)庫(kù)

$ git push origin master
Counting objects: 16, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (16/16), done.
Writing objects: 100% (16/16), 4.58 KiB | 0 bytes/s, done.
Total 16 (delta 5), reused 0 (delta 0)
remote: Resolving deltas: 100% (5/5), completed with 1 local object.
To github.com:xxx/yyy.git
   ca025de..5ae59c1  master -> master

拉取A的遠(yuǎn)程代碼

// 先查看下遠(yuǎn)程代碼倉(cāng)庫(kù)

$ git remote show origin
* remote origin
  Fetch URL: https://github.com/xxx/yyy.git
  Push  URL: https://github.com/xxx/yyy.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

// 添加上游代碼倉(cāng)庫(kù)

$ git remote add upstream https://github.com/aaa/yyy.git

// 或者使用git remote -v查看遠(yuǎn)程代碼倉(cāng)庫(kù)修壕,現(xiàn)在已經(jīng)添加成功

$ git remote -v
origin  https://github.com/xxx/yyy.git (fetch)
origin  https://github.com/xxx/yyy.git (push)
upstream        https://github.com/Datura900607/datura_lj.git (fetch)
upstream        https://github.com/Datura900607/datura_lj.git (push)

// 拉取上游代碼倉(cāng)庫(kù)的代碼

$ git pull upstream master
From https://github.com/aaa/yyy
 * branch            master     -> FETCH_HEAD
Auto-merging readme.txt
CONFLICT (content): Merge conflict in readme.txt
Automatic merge failed; fix conflicts and then commit the result.

xxx@xxx MINGW64 /e/yyy(master|MERGING)

查看代碼狀態(tài)

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        both modified:   readme.txt

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   .idea/workspace.xml

no changes added to commit (use "git add" and/or "git commit -a")

保存修改的本地代碼到緩存區(qū)缓窜,commit本地代碼要寫備注

$ git add --all
warning: LF will be replaced by CRLF in .idea/workspace.xml.
The file will have its original line endings in your working directory.

$ git commit -m "fixed form fork"
[master 5ae59c1] fixed form fork

把本地最新代碼同步到自己的遠(yuǎn)程倉(cāng)庫(kù)

4. 發(fā)送pull request將自己修改的代碼合并到A的遠(yuǎn)程代碼倉(cāng)庫(kù)

在gitlab或者github上發(fā)起pull request 或者new merge request 等待A倉(cāng)庫(kù)的管理員進(jìn)行merge

5. B從A fork一個(gè)遠(yuǎn)程A的代碼倉(cāng)庫(kù)的副本到B的遠(yuǎn)程倉(cāng)庫(kù),修改代碼后push到B的遠(yuǎn)程倉(cāng)庫(kù)

6. 當(dāng)我需要同步B的最新代碼浪腐,拉取B的遠(yuǎn)程代碼到自己的本地

git 命令窗清屏

$ clear

添加B的遠(yuǎn)程代碼倉(cāng)庫(kù),并重命名bbb

$ git remote add bbb https://github.com/bbb/yyy.git

xxx@xxx MINGW64 /e/yyy(master)
// 查看已經(jīng) 添加成功
$ git remote -v
origin  https://github.com/xxx/yyy.git (fetch)
origin  git@github.com:xxx/yyy.git (push)
upstream        https://github.com/aaa/yyy.git (fetch)
upstream        https://github.com/aaa/yyy.git (push)
bbb https://github.com/bbb/yyy.git (fetch)
bbb https://github.com/bbb/yyy.git (push)

從B的遠(yuǎn)程拉取最新代碼 git fetch , git merge

$ git fetch bbb master
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 2), reused 6 (delta 2), pack-reused 0
Unpacking objects: 100% (6/6), done.
From https://github.com/bbb/yyy
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> bbb/master
// 查看修改的地方

$ git diff
diff --git a/readme.txt b/readme.txt
index 80aafc0..3229bc6 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,3 +1,3 @@
 Git is a distributed version control system.  => Git<E6><98><AF><E4><B8><80>
<E4><B8><AA><E5><88><86><E5><B8><83><E5><BC><8F><E7><89><88><E6><9C><AC><E6><8E>                                                                                                                                                                                               <A7><E5><88><B6><E7><B3><BB><E7><BB><9F>
 Git is free software distributed under the GPL.
-console.log('changed by xxx')
\ No newline at end of file
+# console.log('changed by xxx')
\ No newline at end of file

// git fetch 并沒(méi)有merge

$ git merge
Already up-to-date.

直接使用git pull

$ git pull bbb master
From https://github.com/bbb/yyy
 * branch            master     -> FETCH_HEAD
Auto-merging readme.txt
Vim: Error reading input, exiting...
Vim: preserving files...
Vim: Finished.
error: There was a problem with the editor 'vi'.
Not committing merge; use 'git commit' to complete the merge.

不添加B的遠(yuǎn)程代碼倉(cāng)庫(kù)顿乒,直接拉取

$ git pull https://github.com/bbb/yyy.git master
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 1), reused 4 (delta 1), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://github.com/xmc123/datura_lj
 * branch            master     -> FETCH_HEAD
Auto-merging readme.txt
Merge made by the 'recursive' strategy.
 readme.txt | 1 +
 1 file changed, 1 insertion(+)

7. 關(guān)于重置ssh-key

重置ssh-key

$ ssh-keygen -t rsa -C "your github email@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/xxx/.ssh/id_rsa):
/c/Users/xxx/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/xxx/.ssh/id_rsa.
Your public key has been saved in /c/Users/xxx/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Qg09NpPxBdtL3/n8t4za/ssqgf0mhpPSGePUxIy4ZCs special_yjl@163.com
The key's randomart image is:
+---[RSA 2048]----+
|      ...o...    |
|       oB. +     |
|      ..o+* o    |
|     . + . = o ..|
|      + S = . ...|
|     E + = +   ..|
|      . + * o   o|
|       . B +.o+ o|
|        . o.*=o*=|
+----[SHA256]-----+

8. 我還會(huì)回來(lái)的......

    [后續(xù)--git fork 涉及分支](http://www.reibang.com/p/7ec8e2e5b3dc)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末议街,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子璧榄,更是在濱河造成了極大的恐慌特漩,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,635評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件骨杂,死亡現(xiàn)場(chǎng)離奇詭異涂身,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)搓蚪,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,543評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門蛤售,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人妒潭,你說(shuō)我怎么就攤上這事悴能。” “怎么了雳灾?”我有些...
    開(kāi)封第一講書人閱讀 168,083評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵漠酿,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我佑女,道長(zhǎng)记靡,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書人閱讀 59,640評(píng)論 1 296
  • 正文 為了忘掉前任团驱,我火速辦了婚禮摸吠,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘嚎花。我一直安慰自己寸痢,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,640評(píng)論 6 397
  • 文/花漫 我一把揭開(kāi)白布紊选。 她就那樣靜靜地躺著啼止,像睡著了一般。 火紅的嫁衣襯著肌膚如雪兵罢。 梳的紋絲不亂的頭發(fā)上献烦,一...
    開(kāi)封第一講書人閱讀 52,262評(píng)論 1 308
  • 那天,我揣著相機(jī)與錄音卖词,去河邊找鬼巩那。 笑死,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的即横。 我是一名探鬼主播噪生,決...
    沈念sama閱讀 40,833評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼东囚!你這毒婦竟也來(lái)了跺嗽?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書人閱讀 39,736評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤页藻,失蹤者是張志新(化名)和其女友劉穎桨嫁,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體惕橙,經(jīng)...
    沈念sama閱讀 46,280評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡瞧甩,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,369評(píng)論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了弥鹦。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片肚逸。...
    茶點(diǎn)故事閱讀 40,503評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖彬坏,靈堂內(nèi)的尸體忽然破棺而出朦促,到底是詐尸還是另有隱情,我是刑警寧澤栓始,帶...
    沈念sama閱讀 36,185評(píng)論 5 350
  • 正文 年R本政府宣布务冕,位于F島的核電站,受9級(jí)特大地震影響幻赚,放射性物質(zhì)發(fā)生泄漏禀忆。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,870評(píng)論 3 333
  • 文/蒙蒙 一落恼、第九天 我趴在偏房一處隱蔽的房頂上張望箩退。 院中可真熱鬧,春花似錦佳谦、人聲如沸戴涝。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 32,340評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)啥刻。三九已至,卻和暖如春咪笑,著一層夾襖步出監(jiān)牢的瞬間可帽,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 33,460評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工窗怒, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留映跟,地道東北人钝满。 一個(gè)月前我還...
    沈念sama閱讀 48,909評(píng)論 3 376
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像申窘,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子孔轴,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,512評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容

  • 多種多樣的工作流使得在項(xiàng)目中實(shí)施Git時(shí)變得難以選擇剃法。這份教程提供了一個(gè)出發(fā)點(diǎn),調(diào)查企業(yè)團(tuán)隊(duì)最常見(jiàn)的Git工作流路鹰。...
    JSErik閱讀 4,417評(píng)論 2 8
  • 能不能好好說(shuō)話贷洲?不能的時(shí)候是因?yàn)閮?nèi)心先產(chǎn)生了不舒服的感受,這種感受的由來(lái)是別人撞擊了你內(nèi)在的價(jià)值觀晋柱。...
    舒驊閱讀 350評(píng)論 0 0
  • 有些故事有些人注定孤獨(dú)优构,孤獨(dú)到故事的結(jié)局,孤獨(dú)到死后雁竞,唯希望孤獨(dú)的魂魄來(lái)世可以被人好好疼愛(ài)钦椭,不再凄涼
    困了的野貓閱讀 114評(píng)論 0 0
  • 沒(méi)錯(cuò)彪腔,是我沒(méi)有忍住。滿街都是情侶的日子里进栽,躲過(guò)了四下無(wú)人的街道德挣,也躲不過(guò)自己的內(nèi)心,偌大的一個(gè)北京快毛,卻沒(méi)有你的身影...
    托塔啊李天王閱讀 385評(píng)論 0 0