# Working with Git (/notebooks/git)

Clone, pull, and push a repository from a notebook session.

Git works normally in Notebooks: your home is real disk and your identity is already set up. Your
home is [not backed up](/notebooks/storage), so push often.

## Clone and push a repository

<Steps>

<Step>
### Create an access token

Git over HTTPS needs a token, not your password.

- **GitHub**: create a **fine-grained personal access token** with **Contents: Read and write** on
  the repositories you need, and copy it once. See [GitHub's
  guide](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens).
- **Bitbucket**: create a [repository access
  token](https://support.atlassian.com/bitbucket-cloud/docs/create-a-repository-access-token/).
  Bitbucket shows a ready-made clone link that includes the token; you can use that link directly.

Treat the token as a password: never commit it or paste it into a notebook.
</Step>

<Step>
### Clone the repository

Use the Git panel in the JupyterLab sidebar (**Clone a Repository**) and enter the HTTPS URL, or a
terminal:

```bash title="Clone over HTTPS"
git clone https://github.com/<org>/<repo>.git
```

Use the HTTPS URL (ending in `.git`), not the SSH one (`git@...`). For the panel, see the
[jupyterlab-git documentation](https://github.com/jupyterlab/jupyterlab-git).
</Step>

<Step>
### Authenticate once

When git asks for credentials, enter your **username** at the Git provider and paste the **token as
the password**. Git caches it in `~/.git-credentials` in your private home, so later sessions do not
ask again.
</Step>

<Step>
### Commit and push

Your name and email are pre-filled from your Databaas login, so commits are attributed to you with no
`git config` step. New repositories start on `main`.

```bash title="Commit and push"
git add -A
git commit -m "Explore the transactions table"
git push
```
</Step>

</Steps>

## Reset a token that expired or was rotated

Authentication failures are usually an expired token, or a token without access to that repository.
Remove the cached credential and authenticate again on your next git command:

```bash title="Clear the cached token"
rm ~/.git-credentials
```

This removes every cached Git credential, not only the one that failed.

## Push often

Your home is not backed up, so an unpushed commit is the only copy. See [notebook
storage](/notebooks/storage).