Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sloanlance/c14af0280411650415b45bd7a29e867c to your computer and use it in GitHub Desktop.
Save sloanlance/c14af0280411650415b45bd7a29e867c to your computer and use it in GitHub Desktop.
clone-private-github-repo-in-google-colab.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/sloanlance/c14af0280411650415b45bd7a29e867c/clone-private-github-repo-in-google-colab.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"# Clone private GitHub repo in Google Colab"
],
"metadata": {
"id": "96-CIx_nJhJq"
}
},
{
"cell_type": "markdown",
"metadata": {
"id": "mWDZUKixkLFb"
},
"source": [
"Based on the article at the following address, with modifications: https://medium.com/@purba0101/how-to-clone-private-github-repo-in-google-colab-using-ssh-77384cfef18f"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ELXCc6sqczz7"
},
"source": [
"\n",
"## Step 1: Generate a new SSH key\n",
"\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "6ryFWs31Zk-4"
},
"source": [
"# DO NOT give a passphrase when prompted! (-N should prevent that)\n",
"!ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -N ''"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "AUFNH5I6dS6o"
},
"source": [
"## Step 2: Add SSH key fingerprints"
]
},
{
"cell_type": "code",
"metadata": {
"id": "rlDieMPTq7Sz"
},
"source": [
"!ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "lcufJyiueB1N"
},
"source": [
"## Step 3: Get the SSH public key"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "5_CGGAqsIjol"
},
"source": [
"Copy the key text and add it to GitHub following the documentation at: https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account"
]
},
{
"cell_type": "code",
"metadata": {
"id": "S-VtBqoKqv6I"
},
"source": [
"!cat ~/.ssh/id_rsa.pub"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "c-2cz66_e46g"
},
"source": [
"### Step 3.1: Test SSH key"
]
},
{
"cell_type": "code",
"metadata": {
"id": "Yz3_U3cVrETx"
},
"source": [
"!ssh -T git@github.com\n",
"# Hi [username]! You've successfully authenticated, but GitHub does not provide shell access."
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "9RRd_Gh1fE_t"
},
"source": [
"## Step 4: Specify Git configuration settings (Optional)"
]
},
{
"cell_type": "code",
"metadata": {
"id": "wnuznrITr9HV"
},
"source": [
"!git config --global user.email 'your_name@example.com'\n",
"!git config --global user.name 'Your Name'"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "xDSTlWPGfj44"
},
"source": [
"## Clone a private repository from GitHub"
]
},
{
"cell_type": "code",
"metadata": {
"id": "PdzI_WiFrf3c"
},
"source": [
"!git clone git@github.com:YourUserName/repo_name.git"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "A6qzd0fCrj8X"
},
"source": [
"!cd repo_name"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "rUVXlhAMrox3"
},
"source": [
"!touch test.txt\n",
"!git add .\n",
"!git commit -m 'test private repo cloning'\n",
"!git push -u origin master"
],
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment