Skip to main content

Git in the terminal

The command-line terminal in Notebook.link includes an implementation of git called git2cpp that is compiled to WebAssembly and runs entirely in the web browser.

It can be used to create local repositories using git init and to interact with remote repositories such as github and gitlab using git clone, git fetch and git push.

To demonstrate its use in Notebook.link, here are some walkthroughs of typical git workflows.

Clone a remote repository and make local changes​

  1. First open the Git Add-on, enter the name and email address to associate with commits as shown below, and save it.
Complete Git Add-onComplete Git Add-on
  1. Create a new Project in the usual way and enable the Git Add-on by toggling the switch on the bottom right as shown below.
Create new Project using Git Add-onCreate new Project using Git Add-on
  1. Save and launch the Project.

The remaining steps are shown in the video below.

  1. Launch a terminal.
  2. git clone a remote repository from github. This is a public repository so no authentication is required.
  3. cd into the new repository directory.
  4. git status to confirm it is on the main branch.
  5. git log to show some of the commit history.
  6. Checkout a new branch called temp-branch based on main.
  7. Add some extra text to the top of README.md using vim, and save the changes.
  8. head -2 README.md to confirm the file changes.
  9. git status to show that git is aware of the file change.
  10. git add the changed file.
  11. git commit to commit the changes, which prompts for a commit message.
  12. git status to confirm it is on the temp-branch and the change has been committed.
  13. git log -n1 to show the commit message.

Use a private repository with authentication​

This is a similar workflow to that above except that it clones a private remote repository that requires an authentication token. It also pushes a new branch to that remote repository using the same authentication token without having to re-enter it.

It assumes you have already configured and enabled the Git Add-on in your Project (steps 1 and 2 in the workflow above). The remaining steps are shown in the video below.

  1. Launch a terminal.
  2. git clone a private remote repository from github.
  3. The attempt to clone fails, with github replying that authentication is required. Notebook.link therefore displays an 'Enter Git credentials' dialog. The user enters their username and access token and clicks the Submit button. Note that certain types of access token such as github Personal Access Tokens ignore the username provided it is not an empty string.
  4. The clone succeeds, showing that the token is accepted. If the token is not accepted the 'Enter git credentials' dialog will be displayed again; if the dialog is cancelled the clone will be aborted.
  5. cd into the new repository directory.
  6. git fetch to fetch updates from the remote. This is done here to show that the access token was automatically reused rather than a new 'Enter git credentials' dialog being displayed again.
  7. ls -l to show there are just two files in the local repository.
  8. Checkout a new branch with a randomised name, to not conflict with any existing branches on the remote.
  9. Use echo to write some text to a new file called new.txt.
  10. ls -l to show the new file exists.
  11. cat new.txt to confirm the content of the new file.
  12. git add the new file.
  13. git commit to commit the changes, which prompts for a commit message.
  14. git push all branches to the remote, which succeeds showing that the access token was automatically reused rather than a new 'Enter git credentials' dialog being displayed again.
  1. Return to the Git Add-on page, as shown below, to see that the access token for the remote repository has been stored in the Notebook.link secure vault. This token can be deleted from here but it can not be viewed as that would be insecure.
Git Add-on containing tokenGit Add-on containing token

To add a token manually, click the Add token button on the Git Add-on page and fill out the three fields 'URL regex', 'Username' and 'Access token' before saving. Using a regex for the URL lets a single token authenticate multiple remote repositories. A stored token can be deleted with the 'x' to its right, and all tokens can be deleted together using the minus sign next to the 'Add token' button.

Git Add-on token with a URL regexGit Add-on token with a URL regex