Skip to content

Commit

Permalink
Created using Colaboratory
Browse files Browse the repository at this point in the history
  • Loading branch information
murphyk committed May 26, 2023
1 parent 1555c98 commit 31b1013
Showing 1 changed file with 44 additions and 20 deletions.
64 changes: 44 additions & 20 deletions notebooks/tutorials/colab_intro.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"colab": {
"name": " colab_intro.ipynb",
"provenance": [],
"toc_visible": true,
"machine_shape": "hm",
"include_colab_link": true
},
Expand Down Expand Up @@ -2943,27 +2944,21 @@
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "cbae2714-3da4-405e-93d6-32fe1d4bbf4e"
"outputId": "ee3717ed-e9db-4f3b-aa9b-e1cf74b00e7a"
},
"source": [
"\n",
"!rm -rf pyprobml # Remove any old local directory to ensure fresh install\n",
"!git clone https://github.com/probml/pyprobml\n"
"!git clone --depth 1 https://github.com/probml/pyprobml\n"
],
"execution_count": null,
"execution_count": 48,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Cloning into 'pyprobml'...\n",
"remote: Enumerating objects: 11604, done.\u001b[K\n",
"remote: Counting objects: 100% (349/349), done.\u001b[K\n",
"remote: Compressing objects: 100% (200/200), done.\u001b[K\n",
"remote: Total 11604 (delta 181), reused 282 (delta 143), pack-reused 11255\u001b[K\n",
"Receiving objects: 100% (11604/11604), 564.09 MiB | 38.35 MiB/s, done.\n",
"Resolving deltas: 100% (6412/6412), done.\n"
],
"name": "stdout"
"error: did you mean `--depth` (with two dashes)?\n"
]
}
]
},
Expand Down Expand Up @@ -3193,18 +3188,45 @@
"source": [
"## Pushing local files back to github\n",
"\n",
"You can easily save your entire colab notebook to github by choosing 'Save a copy in github' under the File menu in the top left. But if you want to save individual files (eg code that you edited in the colab file editor, or a bunch of images or data files you created), the process is more complex. There are several possible methods.\n",
"You can easily save your entire colab notebook to github by choosing 'Save a copy in github' under the File menu in the top left. But if you want to save individual files (eg code that you edited in the colab file editor, or a bunch of images or data files you created), the process is more complex. There are several possible methods,\n",
"described [here](https://stackoverflow.com/questions/70016169/how-can-i-copy-a-file-from-colab-to-github-repo-directly-it-is-possible-to-sav) \n",
"and [here](https://medium.com/@robertbracco1/configuring-google-colab-like-a-pro-d61c253f7573#6b70).\n",
"Below we describe two other solutions.\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"source": [
"### Use the local terminal\n",
"\n",
"Suppose you clone a repo using something like\n",
"```\n",
"git clone --depth 1 https://github.com/probml/pyprobml.git\n",
"``` \n",
"This will create a folder called `content/pyprobml`. \n",
"You can access this in colab as usual. Now suppose you want to save your edits, eg to a file called `foo.txt`. Follow the steps below.\n",
"\n",
"* Open a terminal window. Then type `git clone --depth 1 https://github.com/probml/pyprobml.git` which will create a folder called `content/pyprobml`. Access this in colab as usual. To save your edits, eg to a file called `foo.txt` do `git add foo.txt` then `git commit -m \"message\"` then `git push`. Github will ask for your username and password. Instead of a password, enter your [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token).\n",
"Open a terminal window inside colab. \n",
"(Or run the commands below in the colab notebook, but prefixed with !. For some reason this fails with the final push command...). Then do the following\n",
"- `git config --global user.email \"murphyk@gmail.com\"`\n",
"- `git config --global user.name\"Kevin Murphy\"`\n",
"- `cd /content/pyprobml`\n",
"- `echo 'this is a test' > foo.txt` # if haven't yet modified the file\n",
"- `git add foo.txt` \n",
"- `git commit -m \"message\"`\n",
"- `git push` \n",
"\n",
"* Try the methods described [here](https://stackoverflow.com/questions/70016169/how-can-i-copy-a-file-from-colab-to-github-repo-directly-it-is-possible-to-sav) or [here](https://medium.com/@robertbracco1/configuring-google-colab-like-a-pro-d61c253f7573#6b70).\n",
"Github will ask for your username and password. Instead of a password, enter your [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token).\n",
"\n",
"* You can try the method described below. However, as of May 2023, this no longer seems to work. \n",
"\n",
"\n"
]
],
"metadata": {
"id": "zYM1T1hWP0bC"
}
},
{
"cell_type": "markdown",
Expand All @@ -3215,6 +3237,8 @@
"### Deprecated method\n",
"\n",
"\n",
"To avoid having to type your PAT every time, you can use the method below. However, as of May 2023, this no longer seems to work.\n",
"\n",
"You first need to do some setup to create SSH keys on your current colab VM (virtual machine), manually add the keys to your github account, and then copy the keys to your mounted google drive so you can reuse the same keys in the future. This only has to be done once.\n",
"\n",
"After setup, you can use the [git_ssh](https://github.com/probml/pyprobml/blob/master/deprecated/scripts/colab_utils.py#L40) function we define below to securely execute git commands. This works by copying your SSH keys from your google drive to the current colab VM, executing the git command, and then deleting the keys from the VM for safety. \n",
Expand Down Expand Up @@ -3493,11 +3517,11 @@
"print(cmd)"
],
"metadata": {
"id": "DkRKbk1LFie7",
"outputId": "e070a99e-0825-4c44-cf38-2eedd807c50a",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"id": "DkRKbk1LFie7",
"outputId": "e070a99e-0825-4c44-cf38-2eedd807c50a"
},
"execution_count": 23,
"outputs": [
Expand Down

0 comments on commit 31b1013

Please sign in to comment.