Git 合并其他 remote 的更新

记录下,好记性不如滥笔头。

Havanna fork 了 leopku 的 centostweak 项目,现在 leopku 的 centostweak 有更新了,下面更新 Havanna fork 的 centostweak 项目。

先把 centostweak fork 的版本获取到本地

^_^ ~ $ git clone git@github.com:Havanna/centostweak.git
Cloning into 'centostweak'...
Enter passphrase for key '/home/havanna/.ssh/id_rsa':
remote: Counting objects: 45, done.
remote: Compressing objects: 100% (28/28), done.
remote: Total 45 (delta 14), reused 44 (delta 13)
Receiving objects: 100% (45/45), 12.03 KiB, done.
Resolving deltas: 100% (14/14), done.
^_^ ~ $ cd centostweak/

查看 fork 版本的别名

^_^ ~/centostweak $ git remote
origin

定义远程 leopku/centostweak 为别名 leopku

^_^ ~/centostweak $ git remote add leopku https://github.com/leopku/centostweak.git

用 fetch 命令获取 leopku/centostweak 的所有分支

^_^ ~/centostweak $ git fetch leopku
remote: Counting objects: 12, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 10 (delta 3), reused 8 (delta 1)
Unpacking objects: 100% (10/10), done.
From https://github.com/leopku/centostweak
* [new branch]      libpath_x86_64 -> leopku/libpath_x86_64
* [new branch]      master     -> leopku/master

注:git pullgit fetch 的区别,git pull 相当于 git fetch && git merge

git merge leopku/master 将 centostweak 的 master 分支的改动合并过来,目前是处与 master 分支,再推送到 origin

^_^ ~/centostweak $ git push origin master
Enter passphrase for key '/home/havanna/.ssh/id_rsa':
Counting objects: 12, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 1.55 KiB, done.
Total 10 (delta 3), reused 0 (delta 0)
To git@github.com:Havanna/centostweak.git
   fe31e79..2c429d3  master -> master

同时推送到两个 remote

$ git remote add name1 https://github.com/aaa/name.git
$ git remote add name2 https://github.com/bbb/name.git
$ git push name1 master
$ git push name2 master

或者 vim .gitconfig

[remote "public"]
 url = git@github.com:aaa/bbb.git
 url = kch@homeserver:ccc/ddd.git

然后一次推送到两个 remote

git push public