=====================
Project collaboration
=====================

Because Data Science & AI Workbench projects are structured as Git repositories, familiar Git rules apply for sharing your changes with project collaborators. Adding a user or group of users to a project as collaborators provides them with access to edit project files and commit changes to the project's remote Git repository. Workbench tracks all changes to projects and lets you know when files have been updated, so you can choose which version to work with.

.. tip::
  
  The *only* project setting collaborators can edit is the default editor. 

.. _share_project:

Adding collaborators to a project
=================================

To add a user or group of users as collaborators for a project:

#. From the **Projects** page, open the project you want to collaborate on.
#. Select |share-nodes| **Share** from the left-hand navigation. 
#. Begin typing a user or group name in the **Add New Collaborator** dropdown to search for matches. Select the correct entry, then click **Add**.

Collaborators added to your project will see it on their **Projects** page, and if others share their projects with you, they'll appear on yours.

Removing collaborators from a project
=====================================

Removing collaborators from a project revokes their access to the project's remote repository, so they will no longer see the project or be allowed to commit and push changes to the repository. 

To remove collaborators from a project:

#. From the **Projects** page, open the project you want to remove collaborators from.
#. Select |share-nodes| **Share** from the left-hand navigation.
#. Click |X| beside the collaborator you want to remove.
#. Click **Remove**. 

.. caution::

   Removing collaborators from a project *while they have a session open* results in a ``500 Internal Server Error`` message for them. Communicate with collaborators prior to removing them from projects. 

Saving vs. committing changes
=============================

When you open a project session, you're working with a local copy of the project's remote Git repository. Changes you *save* only affect your local project repository. When you're ready to update the project or share your updates with others, you must *commit and push* your changes to the project's remote repository.

.. _commit_changes:

Committing and pushing changes
==============================

#. From a project session, click **Commit and push changes** |cloud-arrow-up|. 
#. Select checkboxes for the files you want to commit to your project's remote repository.

   .. caution:: 
      
      If files you've added or modified aren't displayed in this list, verify the changes are saved locally, then try again.

   .. note::

      Some editors create hidden folders that are only used internally to capture the state of your files between auto-save operations. Anaconda recommends you `add hidden folders to your project's .gitignore file <https://git-scm.com/docs/gitignore>`_, so they are excluded from version control.

#. Enter a commit message for your changes. Best practice for commit messages is to make the message descriptive of your changes.
#. If necessary, enter a meaningful label or version number as a **Tag** for your project. This enables you and your project collaborators to manage and deploy specific builds of the project. 

   .. tip:: 

      Any commits pushed to the latest version of a project are included when the project is downloaded, even if you have not tagged the commits to a new version of the project.

#. Click **Commit and Push**. A notification appears informing you that your local changes have been pushed to the project's remote repository.

If your changes conflict with updates made by other collaborators, a list of impacted files will display in red. To resolve your conflicts:

* **Cancel** - This won't resolve any file conflicts, but it will cancel the commit. 
* **Commit** - Overwrite your collaborators' changes. Exercise caution! Collaborators might not appreciate having their work overwritten, and important work could be lost!
* **Selectively Commit** - Commit only those files that don't have conflicts by unchecking the ones highlighted in red. 

.. note:: 
  
  Committing changes to the project's remote repository involves a full synchronization. This means that as you push your local repository changes, any updates that have been committed to the project that do not conflict with the changes you're committing are simultaneously pulled to your local project repository. This means that, after committing your changes, your local project repository will match the remote project repository.

Pulling changes
===============

When working on a project with other users, you will need to manage keeping your local project repository current with changes that they have committed to the project's remote repository. A badge appears on **Pull Changes** |cloud-arrow-down| whenever a commit has been made to the project, indicating that you need to update your local project repository.

To pull changes to your local project repository:

From a project session, click **Pull Changes** |cloud-arrow-down|. If there are no file conflicts, your local repository is updated. 

If the remote repository contains conflicts with changes you have made locally, you can choose one of the following options:

* **Cancel** - This won't resolve any file conflicts, but it will cancel the pull.
* **Keep Theirs and Pull** - Discards your local changes in favor of theirs. Your changes will be lost.
* **Keep Mine and Pull** - Discards changes on the remote repository in favor of your local changes. Their changes will be overwritten.
* **Keep Both and Pull** - This saves the conflicting files with different filenames so you can compare the content of the files and decide how you want to reconcile the differences. 

.. caution::
  
  If you have a file open that has been modified by pulling changes, close and reopen the file for the changes to appear. If you do not, the next time you save the file, you will receive a ``File has been overwritten on disk`` alert in JupyterLab. This alert lets you choose whether to cancel the save, discard the current version and open the version of the file on disk, or overwrite the file on disk with the current version.

.. |cloud-arrow-up| raw:: html

   <svg class="inline" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M389.8 125.2C363.7 88.1 320.7 64 272 64c-77.4 0-140.5 61-143.9 137.5c-.6 13-9 24.4-21.3 28.8C63.2 245.7 32 287.2 32 336c0 61.9 50.1 112 112 112H512c53 0 96-43 96-96c0-36.8-20.7-68.8-51.2-84.9c-13.4-7.1-20-22.5-15.8-37.1c2-6.9 3-14.3 3-22c0-44.2-35.8-80-80-80c-12.3 0-23.9 2.8-34.3 7.7c-14.1 6.7-30.9 2.3-39.9-10.5zM272 32c59.5 0 112.1 29.5 144 74.8C430.5 99.9 446.8 96 464 96c61.9 0 112 50.1 112 112c0 10.7-1.5 21-4.3 30.8C612.3 260.2 640 302.9 640 352c0 70.7-57.3 128-128 128H144C64.5 480 0 415.5 0 336c0-62.8 40.2-116.1 96.2-135.9C100.3 106.6 177.4 32 272 32zM228.7 244.7l80-80c6.2-6.2 16.4-6.2 22.6 0l80 80c6.2 6.2 6.2 16.4 0 22.6s-16.4 6.2-22.6 0L336 214.6V368c0 8.8-7.2 16-16 16s-16-7.2-16-16V214.6l-52.7 52.7c-6.2 6.2-16.4 6.2-22.6 0s-6.2-16.4 0-22.6z"/></svg>

.. |cloud-arrow-down| raw:: html

   <svg class="inline" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M389.8 125.2C363.7 88.1 320.7 64 272 64c-77.4 0-140.5 61-143.9 137.5c-.6 13-9 24.4-21.3 28.8C63.2 245.7 32 287.2 32 336c0 61.9 50.1 112 112 112H512c53 0 96-43 96-96c0-36.8-20.7-68.8-51.2-84.9c-13.4-7.1-20-22.5-15.8-37.1c2-6.9 3-14.3 3-22c0-44.2-35.8-80-80-80c-12.3 0-23.9 2.8-34.3 7.7c-14.1 6.7-30.9 2.3-39.9-10.5zM272 32c59.5 0 112.1 29.5 144 74.8C430.5 99.9 446.8 96 464 96c61.9 0 112 50.1 112 112c0 10.7-1.5 21-4.3 30.8C612.3 260.2 640 302.9 640 352c0 70.7-57.3 128-128 128H144C64.5 480 0 415.5 0 336c0-62.8 40.2-116.1 96.2-135.9C100.3 106.6 177.4 32 272 32zM228.7 299.3c-6.2-6.2-6.2-16.4 0-22.6s16.4-6.2 22.6 0L304 329.4V176c0-8.8 7.2-16 16-16s16 7.2 16 16V329.4l52.7-52.7c6.2-6.2 16.4-6.2 22.6 0s6.2 16.4 0 22.6l-80 80c-6.2 6.2-16.4 6.2-22.6 0l-80-80z"/></svg>
  
.. |share-nodes| raw:: html

   <svg class="inline" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M448 112c0 44.2-35.8 80-80 80c-22.9 0-43.6-9.6-58.1-25l-151 75.5c.8 4.4 1.1 8.9 1.1 13.5s-.4 9.1-1.1 13.5l151 75.5c14.6-15.4 35.2-25 58.1-25c44.2 0 80 35.8 80 80s-35.8 80-80 80s-80-35.8-80-80c0-9.7 1.7-19 4.9-27.7L147.2 299.5c-14.3 22-39 36.5-67.2 36.5c-44.2 0-80-35.8-80-80s35.8-80 80-80c28.2 0 52.9 14.5 67.2 36.5l145.7-72.9c-3.2-8.6-4.9-17.9-4.9-27.7c0-44.2 35.8-80 80-80s80 35.8 80 80zM80 304a48 48 0 1 0 0-96 48 48 0 1 0 0 96zM416 112a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zM368 448a48 48 0 1 0 0-96 48 48 0 1 0 0 96z"/></svg>

.. |X| raw:: html

   <svg class="inline" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path d="M382.1 45.2c2.9-3.4 2.5-8.4-.9-11.3s-8.4-2.5-11.3 .9L192 243.7 14.1 34.8c-2.9-3.4-7.9-3.8-11.3-.9S-1 41.8 1.9 45.2L181.5 256 1.9 466.8c-2.9 3.4-2.5 8.4 .9 11.3s8.4 2.5 11.3-.9L192 268.3 369.9 477.2c2.9 3.4 7.9 3.8 11.3 .9s3.8-7.9 .9-11.3L202.5 256 382.1 45.2z"/></svg>