Methods for using Git with Google Colab

前端 未结 12 797
臣服心动
臣服心动 2020-12-12 11:42

Are there any recommended methods to integrate git with colab?

For example, is it possible to work off code from google source repositories or the likes?

Nei

12条回答
  •  执笔经年
    2020-12-12 12:08

    You can use ssh protocol to connect your private repository with colab

    1. Generate ssh key pairs on your local machine, don't forget to keep
      the paraphrase empty, check this tutorial.

    2. Upload it to colab, check the following screenshot

      from google.colab import files
      uploaded = files.upload()

    3. Move the ssh kay pairs to /root and connect to git

      • remove previously ssh files
        ! rm -rf /root/.ssh/*
        ! mkdir /root/.ssh
      • uncompress your ssh files
        ! tar -xvzf ssh.tar.gz
      • copy it to root
        ! cp ssh/* /root/.ssh && rm -rf ssh && rm -rf ssh.tar.gz ! chmod 700 /root/.ssh
      • add your git server e.g gitlab as a ssh known host
        ! ssh-keyscan gitlab.com >> /root/.ssh/known_hosts
        ! chmod 644 /root/.ssh/known_hosts
      • set your git account
        ! git config --global user.email "email"
        ! git config --global user.name "username"
      • finally connect to your git server
        ! ssh git@gitlab.com
    4. Authenticate your private repository, please check this Per-repository deploy keys.

    5. Use ! git@gitlab.com:{account}/{projectName}.git
      note: to use push, you have to give write access for
      the public ssh key that you authenticate git server with.

提交回复
热议问题