Save a notebook to GitHub

You can save the contents of a notebook instance to GitHub to back up your notebook, as well as make it available to others to use.

To save a notebook to GitHub, follow these steps:

  1. Create a GitHub repository.

    If you do not already have a GitHub repository, you must create one. When you create your GitHub repository, initialize the repository with a README file to ensure that a master branch is created.

    Initialize a GitHub repository with a README file

  2. Configure your notebook instance with your GitHub user information.

    1. Open your notebook instance by clicking Open JupyterLab.

    2. Select Git -> Open Terminal to open a Git terminal window.

      Open a Git terminal

    3. In the Git terminal window, enter the following commands to configure your Git user name and email:

      git config --global user.name "your-name"
      git config --global user.email "your-email"
      
    4. Close the Git terminal window.

  3. Clone your GitHub repository in your notebook instance.

    1. Copy the URL for your GitHub repository. You can get this from the Clone or download option in your GitHub repository.

      Get GitHub repository URL

    2. In your notebook instance, select the folder where you want to clone the GitHub repository. For example, the home folder as shown below:

      Notebook home folder

    3. Click the Git clone button.

      Clone repository button

    4. When prompted, paste in the URL for your GitHub repository that you copied earlier. Then click Clone.

      Paste repository URL and clone

  4. Your notebook instance shows your repository as a new folder. If you do not see your cloned GitHub repository as a folder, click the Refresh file list button, as shown below:

    File list and refresh button

  5. Add a new notebook to your notebook instance.

    Select File -> New -> Notebook. This creates a new notebook named "Untitled.ipynb". Select the kernel for your new notebook. For example, "Python 3". You can also create a Python 3 notebook using the Launcher.

    Add a notebook file

  6. Select the Git tab. Your new notebook is listed in the Untracked grouping.

    Untracked notebook

    Right-click the new notebook and select Track to add the new notebook as a file for your GitHub repository. Your notebook is now added to the Staged grouping in the Git tab.

    Staged notebook

  7. To commit your new notebook to your GitHub repository, add a commit comment in the Git tab and click the Commit button.

  8. Select Git -> Open terminal to open a Git terminal window.

    Enter the git push command in the Git terminal window. When prompted, enter your GitHub username and password.

    When the git push command completes, your committed files have been added to your GitHub repository.

Var denne siden nyttig? Si fra hva du synes:

Send tilbakemelding om ...