Colab 与 gitlab、github 之间用 git 同步

Colab 是谷歌提供的免费 Jupyter 服务,可使用 GPU。但由于每次的 VM (虚拟机)登出后就会毁掉。如何将一个项目里的程序或数据同步到 Colab则往往比较麻烦。尽管谷歌盘也可以挂到 Colab 里用,但步骤也比较麻烦,另外 github 或 gitlab 的项目和谷歌盘的同步也并不直接。因而,能直接将Colab 的 VM 与 github 或 gitlab 同步就会节省时间。而且,程序再 Colab 上运行完后的更新也可以在VM消失前及时同步到github 或 gitlab 上保存。

Colab 与 gitlab、github 之间用 git 同步功三步。

  • 生成 私钥-公钥 对,公钥 上传到 gitlab或 github,私钥拷到系统剪贴板里备用。
  • 在colab里的 jupyter 里:
    key = \
    '''
    私钥拷到这里
    '''
    ! mkdir -p /root/.ssh
    with open(r'/root/.ssh/id_rsa', 'w', encoding='utf8') as fh:
        fh.write(key)
    ! chmod 600 /root/.ssh/id_rsa
    ! ssh-keyscan gitlab.com >> /root/.ssh/known_hosts
  • 然后就可以按正常 git 管理运作了:
    ! git ... 

猜你喜欢

转载自www.cnblogs.com/vpsblog/p/9568874.html