- 先在自已的本機電腦產生
SSH Key
先建立第一個 github 帳號的 ssh key
# ssh-keygen -t rsa -b 4096 -f github_account_1
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): (若是沒有要使用密碼,直接按Enter即可)
Enter same passphrase again: (若是沒有要使用密碼,直接按Enter即可)
Your identification has been saved in github_account_1.
Your public key has been saved in github_account_1.pub.
The key fingerprint is:
SHA256:lqJlY/txd9Ad8gka8GRk9/bJi8sKaASrxhKx5wONHBQ Nobody@Ubuntu.local
The key's randomart image is:
+---[RSA 4096]----+
| o*.+ o . |
Host github_account_1.github.com
| o o + = o |
| E . = + |
| .. . o + . |
| .o* S . = |
| .+= * o . o . |
| ooo. * . . . |
| .++oo = . . |
| .++o.o ..o |
+----[SHA256]-----+
再建立第二個 github 帳號的 ssh key
# ssh-keygen -t rsa -b 4096 -f github_account_2
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): (若是沒有要使用密碼,直接按Enter即可)
Enter same passphrase again: (若是沒有要使用密碼,直接按Enter即可)
Your identification has been saved in github_account_2.
Your public key has been saved in github_account_2.pub.
The key fingerprint is:
SHA256:lqJlY/zkd9Ad89ka7GRk9/bJi8sKaASrxhKx5wOPWDBS Nobody@Ubuntu.local
The key's randomart image is:
+---[RSA 4096]----+
| o*.+ o . |
Host github_account_2.github.com
| o o + = o |
| E . = + |
| .. . o + . |
| .o* S . = |
| .+= * o . o . |
| ooo. * . . . |
| .++oo = . . |
| .++o.o ..o |
+----[SHA256]-----+
- 請將自已的
SSH Public Key
分別上傳到自已不同 Github 帳號
- 請登入自已的 Github 後,請點選瀏覽器右上角會有一個自已的 Avatar,會出現一個下拉式的選單
- 點選『 Settings 』
- 點選『 SSH and GPG Keys 』
- 點選『 New SSH Key 』,會出現一個畫面,分別有二個地方要填寫,一個是叫
Title
&Key
,Title
的部份,我都習慣輸入自已自定的檔名,Key
的部分,則是請把自已的SSH Public Key
給貼上來即可
- 點選 『 Add SSH Key 』,這樣就算設定完成了
- 設定 SSH Config 連結自已的 Github
請到
~/.ssh
目錄下,建立檔案叫 『 config 』
,並直接編輯它Host github_account_1.github.com
HostName github.com
User git
IdentityFile ~/.ssh/github_account_1
IdentitiesOnly yes
Host github_account_2.github.com
HostName github.com
User git
IdentityFile ~/.ssh/github_account_2
IdentitiesOnly yes
將上面設定完成後,請記得存檔後離開,這邊就完成設定。
- Clone 自已的 Github Project
- 請到自已的 Github Project 的頁面後
- 點選『 clone or download 』 會出現一個小小畫面
- 點選小小畫面的右上角的『 Use SSH 』
- 再點選小小畫面中 URL 旁的『 複製鈕 』,即可將自已的連結給複製起來了
- 再回到 Terminal 上,輸入
git clone git@github_account_1.github.com:nobody/ProjectName.git
,這樣就完成下載了
- 設定 Github Upstream
請先到自已的專案底下,執行
git remote -v
# git remote -v
origin git@github_account_1.github.com:nobody/ProjectName.git (fetch)
origin git@github_account_1.github.com:nobody/ProjectName.git (push)
由於之前有先 git clone 下來自已的專案的 repository,預設就會是用
origin
,因為我專案是從別人的專案 fork 過來的,所以我們為了要跟原本 fork 過來的專案要同步,必須要在自已目前的專案下,建立 upstream
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
接著我們再執行一次
git remote -v
# git remote -v
origin git@github_account_1.github.com:nobody/ProjectName.git (fetch)
origin git@github_account_1.github.com:nobody/ProjectName.git (push)
upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)
- 同步 Fork 回來的專案
- 將 upstream 抓下來
# git fetch upstream remote: Counting objects: 75, done. remote: Compressing objects: 100% (53/53), done. remote: Total 62 (delta 27), reused 44 (delta 9) Unpacking objects: 100% (62/62), done. From https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY * [new branch] master -> upstream/master
- 切換到
master
branch# git checkout master Switched to branch 'master'
- 把
upstream/master
上有改變的檔案,通通都 Merge 回到自已的 localmaster
branch# git merge upstream/master Updating a422352..5fdff0f Fast-forward README | 9 ------- README.md | 7 ++++++ 2 files changed, 7 insertions(+), 9 deletions(-) delete mode 100644 README create mode 100644 README.md
- 同步完成後,還需要把剛更新的資料,推回去到自已的 Github
# git push Enumerating objects: 1, done. Counting objects: 100% (1/1), done. Writing objects: 100% (1/1), 657 bytes | 657.00 KiB/s, done. Total 1 (delta 0), reused 0 (delta 0) To git@github_account_1.github.com:nobody/ProjectName.git 76c826c..89f8a8a master -> master
Reference:
沒有留言:
張貼留言