Javascript required
Skip to content Skip to sidebar Skip to footer

How to Upload Jupyter Notebook on Github

Jupyter Notebook is a spider web-based development tool that makes it easier for developers to manage projects. With a user-friendly interface, Jupyter includes interactive elements to create and share alive documents that contain code, visuals, equations, and even narrative texts.

I've already written almost how to install Jupyter Notebook in my piece "Jupyter Notebooks: The Web-Based Dev Tool You lot've Been Seeking," so you lot should read through that tutorial to get Jupyter upwards and running.

Thing is, with a default Jupyter installation, you miss out on GitHub integration. And given how so many developers depend on the likes of GitHub, this is a feature that is sorely missed.

Fortunately, a developer has created an extension that makes information technology possible for you to employ Jupyter with GitHub. Unfortunately, since the developer created the extension for Jupyter/GitHub, things have changed on the side of GitHub, and then in that location's one caveat to using this tool (I'll explain later). But fifty-fifty with that caveat, this extension is a proficient way to keep your Jupyter Notebooks in sync with a GitHub repository (otherwise, all of those notebooks will remain on your local automobile).

Allow'due south get these two pieces of technology connected.

Before you showtime this procedure, make sure you've taken care of getting Jupyter installed. Make certain y'all don't launch a notebook yet. We'll do that in a bit.

Installing the Extension

You've already installed the necessary dependencies for Jupyter (Python and pip). You now demand to install the Jupyter GitHub extension. Log into your machine that contains Jupyter and open a final window. From the CLI, consequence the following commands:

alias pip=pip3

pip install git+https://github.com/sat28/githubcommit.git

jupyter serverextension enable --py githubcommit

jupyter nbextension install --py githubcommit --user

jupyter nbextension enable githubcommit --user --py

The above commands will install the extension and make certain it is available for all notebooks.

Install the remaining dependencies

Y'all probably already take git installed, simply on the off-chance you don't, issue the control (I'm demonstrating on Ubuntu Desktop 21.04):

sudo apt-get install git -y

If you're using a Red Hat-based distribution, that command would be:

sudo dnf install git -y

Generate SSH keys

Y'all'll also need SSH keys (and so you can clone the necessary repository). For this, run the command:

ssh-keygen

Brand sure to accept the defaults and give the central a unique and strong password.

Once you've generated the key, view the public key with the control:

less ~/.ssh/id_rsa.pub

Copy the contents of that cardinal and caput over to your GitHub business relationship. Go to Settings > SSH and GPG keys and click New SSH Fundamental. In the resulting window, paste the SSH central you just generated, give it a name, and click Add together SSH Key (Figure 1).

Effigy 1: Calculation an SSH primal to GitHub.

Clone the Repository

We need to clone the extension repository, with the control:

git clone [email protected]:sat28/githubcommit.git

Yous will exist asked for the countersign for your SSH fundamental you just created. When this finishes, a new directory will be created, named githubcommit.

With the repository cloned, allow's make sure Git knows who we are. Issue the following two control:

git --global user.email EMAIL

git --global user.name Proper name

Where EMAIL is your email address and NAME is your proper noun.

Create a GitHub Access Token

Next, you demand to create a GitHub access token. Go to your GitHub account and then to Settings > Developer Settings > Personal Admission Tokens. Click Generate New Token then, in the resulting window, give it a proper name and check the boxes for repo and write:packages. Scroll to the lesser and click Generate token. You'll then demand to re-create that access token to your clipboard.

Configure the Extension

Modify into the githubcommit folder with the command:

cd githubcommit

Open the env.sh configuration file with the command:

nano env.sh

In that file, yous must configure the following section:

Where:

  • REPONAME is the name of a GitHub repository you'll utilize for this.
  • Co-operative is the repository branch (probably "principal")
  • USERNAME is your GitHub username
  • E-mail is the e-mail address associated with your GitHub account
  • ATOKEN is the access token you simply created.

Save and close the file.

Source the env.sh file and launch a notebook

The next step is to source the env.sh file with the command:

source ~/githubcommit/env.sh

You lot volition exist prompted for your SSH key countersign. Once you lot've done that, the repository y'all configured in the env.sh file will clone to your local drive (in your home directory). When that completes, alter into the new directory that cloned from your GitHub repository (in my case it was named newstack).

From inside that directory, launch the notebook with the command:

jupyter notebook --ip 0.0.0.0

Your notebook should open to reveal all of the files from your GitHub repository (Figure ii).

Figure two: Jupyter Notebook with files from the newstack repository I created.

If you create a new file or open up one, you'll now see a GitHub logo in your notebook (Effigy 3).

Figure three: The GitHub logo at present shows upward in the Jupyter Notebook.

Here'south where the caveat comes into play. Y'all should be able to click that push and then commit any new code to the connected GitHub repository. Unfortunately, it'due south not working. I have a feeling this is because of the changes GitHub has made recently to hallmark. Considering of that, it'south on the developer to fix this trouble.

Fortunately, I have a workaround.

Later you've created all of your new files and are finished working in Jupyter Notebook, they'll all be found in the directory pulled down from your configured GitHub repository. In my case, I used a examination repository I created on GitHub, named newstack.

Change into that folder and and then get through the usual process with git:

git add .

git commit -m "Added new files"

git button

In one case y'all've taken care of the above steps, all of your new files will be uploaded to the GitHub repository.

The second caveat is that Jupyter doesn't automatically pull downwardly whatsoever new files created by other teammates or from within GitHub itself. For that, get back to the terminal window and consequence the command:

git pull

In other words, to push and pull new content to and from GitHub, you must use the control line (at least until the developer fixes the event). Only fifty-fifty with having to do this, existence able to integrate Jupyter Notebooks with GitHub makes the tool fifty-fifty more useful.

Hopefully, former soon, the developer will resolve the event with the push and pull of content. Until and so, you can get around the bug with a little manual git pull and git push button.

humphreythourbsixot48.blogspot.com

Source: https://thenewstack.io/integrate-jupyter-notebooks-with-github/