講個秘訣:加快 git pull 和 git push 速度

SSH 有個功能是可以沿用已經存在的 host 連線,如果再連一次就會比較快。首先編輯 ~/.ssh/config 加上:


ControlMaster auto
ControlPath /tmp/ssh_mux_%h_%p_%r

接著讓我們一直掛著 GitHub 的 SSH 連線……


ssh -N git@github.com

讓我們實驗看看效果如何:

使用前:


> time git pull

real	0m3.117s
user	0m0.055s
sys	0m0.045s

使用後:


> time git pull

real	0m0.765s
user	0m0.037s
sys	0m0.042s

嗯,效果非常好。

出處:GitHub hack: speed up git push and git pull

參與討論

8 則留言

  1. 建議除了ControlMaster 及 ControlPath、還要指定ControlPersist
    (設定時間,如https://github.com/PeterDaveHello/Unitial/blob/master/ssh_config)

    這部分在Open SSH Manual有說明(http://www.openssh.com/manual.html):
    > When used in conjunction with ControlMaster, specifies that the master connection should remain open in the background (waiting for future client connections) after the initial client connection has been closed.

    這樣就不用特別開一個連線掛在那邊,反正時限內持續有人在重用連線,那他就會繼續活著~

發佈留言

發表迴響