Work with projects in a Git repository
To enable collaboration with external stakeholders or the data science community at large, you can import projects from a Git repository and push project assets to the external Git repository.
The Git integration provides a flexible source code management method to track, back up, and collaborate on a project with multiple users. Collaborators in Git and in IBM® Watson™ Studio can push their changes to the repository so that everyone has access to the changes.
Complete the following tasks to integrate with an external GitHub repository:
- Prepare your repository
- Enable your account to access the Git repository
- Import a project from a Git repository
Complete the following tasks to collaborate on the project:
- Add assets to the project in IBM Watson Studio
- Commit and push changes to a Git repository
- Pull changes from a Git repository
- Merge changes in a Git repository
If you need to sync up your local copy with the remote repository, you can Reset your local copy of the project.
Prepare your repository
Some files need to be in a specific repository folder to display and behave appropriately in IBM Watson Studio.
If you pre-populate the repository, ensure that your repository includes the following folders for each type of asset:
| Asset type | Folder name |
|---|---|
| Jupyter notebooks (.ipynb files) | jupyter |
| Zepplin notebooks (.json files) | zepplin |
| RStudio assets | rstudio |
| Data sets | datasets |
| Models | models |
Files that are not under one of these folders are displayed in the Other Files list in the interface.
Enable your account to access the Git repository
Before you can work with assets in a Git repository, you must enable your IBM Watson Studio account to access the Git repository by creating a personal access token and adding it to your IBM Watson Studio account.
To enable your account to access the Git repository:
- Generate your personal access token for the version of Git where the repository exists:
Version Instructions GitHub - Go to https://github.com/settings/tokens.
- Click Generate a personal access token.
- On the New personal access token page, select the
repo scope so that you can import assets from the repository and commit and
push changes to the repository.
Note: You can select additional scopes, but repo is the minimum required scope. - Click Generate token and copy the token that is generated.
GitHub Enterprise - Go to your GitHub Enterprise deployment.
- Go to Settings and then select
- Click Generate a personal access token.
- On the New personal access token page, select the
repo scope so that you can import assets from the repository and commit and
push changes to the repository.
Note: You can select additional scopes, but repo is the minimum required scope. - Click Generate token and copy the token that is generated.
Bitbucket - Go to https://bitbucket.org.
- Go to Bitbucket Settings and select App passwords.
- Click Create app password.
- On the Add app password page, select the Write or
Admin under Repositories so that you can import
assets from the repository and commit and push changes to the repository.Note: You can select other permissions, but Write or Admin permissions on the repository are required.
- Click Create and copy the token that is generated.
Bitbucket Server - Go to your Bitbucket Server deployment.
- See the Bitbucket Server documentation for information on generating personal access tokens.
- Add the personal access token to your IBM Watson Studio user
account:
- Click your avatar and select Settings.
- Open the Integrations tab and click add token.
- Select the platform on which you generated the token.
- Paste the token that you copied into the Access Token field.
- If prompted, specify your Git Host URL and your username.
- Give the token a meaningful name and click Create.
Import a project from a Git repository
After you save the access token to your user account, you must create a project for the Git repository.
Git projects are managed externally; therefore, collaborators must be added to the project in the external repository and each user who wants to access the repository from IBM Watson Studio must import a copy of the project into IBM Watson Studio.
You can import both public and private repositories.
To create a project for a Git repository:
- Open the Projects page and click Add Project.
- Go to the From Git repository tab.
- Select the access token that is associated with the Git deployment where the repository exists.
- Enter the URL of the repository.Tip: To get the correctly formatted version of repository URL:
- On GitHub, click Clone or download. Ensure that the dialog is called
Clone with HTTPS. If it is not, click Use HTTPS. Then,
copy the URL, which ends with
.git - On Bitbucket, click Clone. Ensure that the HTTPS
option is selected. Then, copy the URL, which ends with
.git
- On GitHub, click Clone or download. Ensure that the dialog is called
Clone with HTTPS. If it is not, click Use HTTPS. Then,
copy the URL, which ends with
- By default, the project has the same name as your repository, but you can rename the project.
After you create the project, the assets from the repository are displayed in the project in IBM Watson Studio.
Add assets to the project in IBM Watson Studio
You can add assets to the project in IBM Watson Studio. However, when you add an asset to the project, your changes remain in your local copy of the repository until you commit and push the changes to the remote repository.
Each type of asset is added to a specific folder in the repository:
| Asset type | Folder name |
|---|---|
| Jupyter notebooks (.ipynb files) | jupyter |
| Zepplin notebooks (.json files) | zepplin |
| RStudio assets | rstudio |
| Data sets | datasets |
| Models | models |
Commit and push changes to a Git repository
Any assets you add to the project remain in your local copy of the project until you commit and push the changes to the remote repository.
To commit your changes to the local copy of the repository:
- From the Git Actions menu (
), select
Commit. - Specify the files that you want to add with the commit and enter a commit message.
- Click Commit.
- Enter a commit message and then click Commit and push.
- From the Git Actions menu (
), select
Push.If your local copy is behind the repository copy, you should pull the latest changes from the remote repository and merge the changes with your local copy before you push your changes to the remote repository.
- If you want to create a release from the project, enter a version tag for the release.
- Click Push.
Pull changes from a Git repository
If a collaborator adds or edits an asset on the remote Git repository, you must pull the change from the remote repository before it appears in your local copy of the project.
- Commit the changes to the remote repository
- Export a copy of the project.
- From the Git Actions menu (
), select
Pull. - If your local copy is ahead of the remote repository, you must merge your changes. For more information, see Merge changes in a Git repository.
Merge changes in a Git repository
If you pull changes from the remote repository that conflict with changes in your local copy, you must merge the changes in one of the following ways:
- Automatic resolution: Strategy: theirs
- Rerun the Git pull but automatically drop your local changes in a merge conflict.
- Automatic resolution: Strategy: ours
- Rerun the Git pull but automatically drop the remote changes in a merge conflict.
- Manual resolution: Open terminal
- Open a web terminal in a new page so you can resolve the merge conflicts by command line, for
example, using
git,vi, orwindiff.When you resolve the merge conflicts, stage the conflicted files in the Git status summary panel and click the Complete Merge button.
- Manual resolution: Resolve locally
- Resolve merge conflicts locally using your own merge conflict solution:
- Export the project as a ZIP file to your local machine.
- Use your own tools such as Eclipse to resolve the conflicts.
- Drag the finished project into the Replace project page to upload it back into IBM Watson Studio.
- In the Git conflict resolution summary panel, stage the conflicted files and click the Complete Merge button to overwrite the files.
- Discard all changes and revert to a past commit (not recommended)
- From the Git Actions menu (
), select
Commit history and revert to a previous commit.
Until you resolve the merge conflicts, your project will wait in merge state.
Reset your local copy of the project
If you make changes to the local copy of your project but decide that you don't want to keep the changes, you can reset your project by pulling the current version of the project from the remote repository.
Resetting your local copy also enables you to sync up with other collaborators in the project.
To reset your project:
- Go to the Projects page.
- From the actions menu for the project, select Reset.
- Click Reset project.