# Git integration (using GitLab)

A Cloud Pak for Data project can be integrated with a git repository.

## Create an empty repository

Use the GitLab menu to create a project and an empty repository.

## Generate a token in GitLab

To create a token for GitLab, login to [GitLab](https://about.gitlab.com/), click on your user account in the top right and choose `Settings`:

![GitLab user account](https://2515897395-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0YTFb_WdaBDnhlXs-q%2F-M0YU2pd2LZNZHAOQxfO%2F-M0YU3wD2lMvqyXPO9PB%2FGitLabUserAccount.png?generation=1582217081988516\&alt=media)

From the left navigation bar select `Access tokens` and fill in the _name_, _expiration date_, and check the boxes for _read\_api_, _read\_repository_ and _write\_repository_. Finally, click `Create personal access token` button:

![GitLab select Access Tokens](https://2515897395-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0YTFb_WdaBDnhlXs-q%2Fsync%2F6a69e8d31ad0f198917f9f1b425d7133e57b3840.png?generation=1595273056390258\&alt=media)

On the resulting page, you'll see your personal access token. Copy this.

> NOTE: This token gives access to your git repository. Do not share with anyone.

![GitLab copy Access Token](https://2515897395-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0YTFb_WdaBDnhlXs-q%2F-M0YU2pd2LZNZHAOQxfO%2F-M0YU3wHqot741mib4Ia%2FGitLabCopyToken.png?generation=1582217079972296\&alt=media)

Now go back to the Cloud Pak for Data _Create project_ page and we'll add the token.

## Create a project with git integration

Go the (☰) menu and click _Projects_

![(☰) Menu -> Projects](https://2515897395-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0YTFb_WdaBDnhlXs-q%2Fsync%2Fc01f89483ecad35450f6b873f7d9e6476d965cc1.png?generation=1595273053628966\&alt=media)

Click on _New project +_

![Start a new project](https://2515897395-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0YTFb_WdaBDnhlXs-q%2Fsync%2F997eb4a4f9aa46b52231043d3c747f16a9222f8f.png?generation=1595273053727549\&alt=media)

Create a new project

* Choose `Analytics project` and click _Next_.
* Click on `Create an empty project`.
* Give the project a name.
* Click the box for `Integrate this project with Git`.

Click on `New Token +`

* Select `Gitlab` in the `Platform` pulldown.
* Paste the token that you have created under `Access token`.
* Enter your GitLab username and give your token a name.
* Click _Continue_.

Use the `Token` pulldown and select the token you created.

Put in the repository URL, select a branch, and click `Create`.

![Create Project with git](https://2515897395-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0YTFb_WdaBDnhlXs-q%2Fsync%2F4957cc0eb335154187046773edbe67ef40357506.png?generation=1595273040821159\&alt=media)

When project creation completes, click on `View new project`.

## Create assets and push to git

Now if we create an asset in the project, we can push to git.

At the project overview, click the `Add to project +` button, and choose `Notebook`:

![Add a new asset](https://2515897395-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0YTFb_WdaBDnhlXs-q%2Fsync%2F48be05b81e1bc4ef7ca257929f8f348837b6dfe4.png?generation=1595273061938885\&alt=media)

On the next panel select the _From URL_ tab, give your notebook a name, provide the following URL, and choose the Python 3.6 environment:

```bash
https://raw.githubusercontent.com/IBM/cloudpakfordata-telco-churn-workshop/master/notebooks/TelcoChurnICP4D.ipynb
```

Click _Create notebook_.

Now, go back to the top-level project page, click the "circular arrow" sync-icon, and choose `Pull and push`:

![git pull and push](https://2515897395-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0YTFb_WdaBDnhlXs-q%2Fsync%2Fd6fa315ea4be7e43a0325d6c859b3ab026097e6f.png?generation=1595273042549245\&alt=media)

On the _Confirm Sync_ page, select your token, check the box for your notebook, and click `Sync`:

![git confirm sync](https://2515897395-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0YTFb_WdaBDnhlXs-q%2Fsync%2Fdb94933244dbb5df5594814f96e521ee754c3ddc.png?generation=1595273019456933\&alt=media)

The next screen will verify "Did you remove credentials from assets?". After confirming this, click `Continue export`.

After syncing, the screen will show Success. You can click `Back to project`.

You can integrate git into your workflow in your usual way, syncing with teammates via 'git pull' and using 'git push' to upload your changes to the git remote repository.
