Providing a Real-Time Complement for Git-Based Collaboration
Tags: productivity, javascript, collaboration, webdev
Published: 2019-06-10 15:59:56

---
title: Providing a Real-Time Complement for Git-Based Collaboration
published: true
description: 
tags: productivity, javascript, collaboration, webdev
series: Visual Studio Live Share
---

Every day, millions of developers collaborate using one of the most fundamental tools in software: [Git](https://git-scm.com/). As a [distributed version control system](https://en.wikipedia.org/wiki/Distributed_version_control) (DVCS), Git enables you to work with a personal, offline copy of a codebase, and when ready, [carefully merge](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository) your changes into a [hosted repository](https://GitHub.com) that's shared amongst the team. This supports an extremely flexible form of [asynchronous collaboration](https://devops.com/collaboration-types), and is integral to maintaining a project's history. 

However, while Git represents the foundation for **team-wide, long-term collaboration**, it wasn't built for **short-term, synchronous interactions**. For example: when you’re pair programming, mentoring another developer, or simply seeking help from a peer, you need a **real-time, conversational experience**, that's highly-iterative, and doesn’t require impacting project history in order to prototype or exchange ideas. This is exactly why we built [Visual Studio Live Share](https://aka.ms/vsls): to provide a **real-time complement for Git**.

In a [previous post](https://aka.ms/vsls-why), I illustrated how Live Share enables a unique form of collaboration, for a diverse set of [developer use cases](https://aka.ms/vsls-usecases). However, since most teams will use Live Share **in conjunction with version control**, I wanted to demonstrate how it can provide a better-together experience for Git-based workflows, across the entire developer lifecycle (e.g. code reviews, merge conflicts, pull requests). Let's see how this looks!

## Collaboration Between Commits

When you share a project using Live Share, everyone in the session can immediately view and edit files, **without needing to download or clone anything**. However, having access to file contents is only part of the story, and for Git-versioned projects, there’s another piece of fundamental context: the state of the [working directory](https://git-scm.com/book/en/v1/Getting-Started-Git-Basics#The-Three-States). Without this, participants couldn’t identity in-flight/uncommitted changes, which is critical to focusing discussions and understanding/remembering what’s been done.

While in a Live share session, you can simply open your `Source Control` tab, and immediately view the list of files that have been changed and/or staged. From there, you can click any file (or [gutter indicator](https://code.visualstudio.com/docs/editor/versioncontrol#_gutter-indicators)) to view its diff, and even discard undesirable changes. It looks and feels like everyone is working with their own local copy, but without requiring changes to be committed, pushed or pulled. This enables a form of **real-time, peer-to-peer collaboration, "on top of" Git's distributed file system** 🚀

![Shared Diffs](https://user-images.githubusercontent.com/116461/59164447-984cc500-8ac1-11e9-934d-4463b0e303de.gif)

<em>A Live Share guest (left) viewing and discarding changes directly in their editor</em>

Additionally, Live Share allows you to add comments to any line of code, which when combined with shared diffs, enables you to perform entirely **real-time, ad-hoc code reviews**, without needing to rely on other tools or services. We've found this to be extremely powerful for teams that do trunk-based development, or are just looking to get some initial advice before sending out a team-wide pull request 🔥

![Comments](https://user-images.githubusercontent.com/116461/59165538-46606b00-8ad2-11e9-8554-6a98a2c65c97.gif)

<em>A Live Share guest (left) communicating with the host (right) via code comments</em>

## Learning From History

In addition to viewing the state of a project's working directory (i.e. uncommitted changes), there are also times when it's valuable to view the **commit history of a file**, in order to understand when specific changes were introduced, and by whom. Visual Studio Code doesn't provide an in-box solution for viewing commit history, however, gaining this capability is just an extension-install away!

[GitLens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens) is one of the most popular extensions in the marketplace, and among other things, it provides a rich experience for navigating and searching Git history. Even cooler, it's fully [Live Share enabled](https://aka.ms/vsls-awesome), and therefore, if a guest has it installed, they can explore project history just as if they were working against a local repository. 

![GitLens](https://user-images.githubusercontent.com/116461/59164713-c46a4500-8ac5-11e9-9a9f-04a1b3663166.gif)

<em>A Live Share guest (left) using the GitLens extension to navigate a file's history</em>

## Collaboration Can Have Conflicts

When you're collaboratively editing a file in a Live Share session, updates are synchronized in real-time using an algorithm called [operational transforms](https://en.wikipedia.org/wiki/Operational_transformation). As a result, multiple developers can edit the exact same line/file, and rest assured that any conflicts will be automatically handled (just like Google Docs/Word). However, since Git is an asynchronous form of collaboration, conflicts can sometimes occur when multiple developers edit the same line, but in different ways (e.g. you rename a variable that I deleted), and you're trying to [merge the competing changes together](https://help.github.com/en/articles/resolving-a-merge-conflict-using-the-command-line).

While some merge conflicts can be simple to resolve, others can be quite difficult, depending on the number of conflicts, and the context behind the competing changes. With Live Share, you can simply invite the necessary developer(s) into a session, and walk through each conflict in real-time. Additionally, since Live Share supports [independent editing/navigation](https://dev.to/lostintangent/collaboration-doesn-t-come-in-one-size-fits-all-33ai), you can choose to handle the conflicts one-by-one, or divide-and-conquer them. It's completely up to you!

![MergeConflict](https://user-images.githubusercontent.com/116461/59165233-b6b8bd80-8acd-11e9-8f98-0617cdd15350.gif)

<em>A Live Share guest (left) collaboratively resolving a merge conflict in real-time</em>

## Pull Requests

Once you've completed your work, you might decide that it's time to create a pull request, so you can socialize the change across the team, and solicit broader feedback. Since PR discussions are entirely asynchronous (just like Git!), communication occurs via comments, which enables a lightweight way to iterate, regardless of everyone's schedule. However, sometimes a review goes on long enough, that it becomes worth talking through your changes with someone in real-time, since synchronous conversations can be more responsive.

If you install the [GitHub Pull Requests](https://marketplace.visualstudio.com/items?itemName=GitHub.vscode-pull-request-github) extension, it enables you to check out your PR branches, and view their respective changes and comments, directly within Visual Studio Code. Even cooler, since this extension is fully Live Share-enabled, you can start a collaboration session while you're in "review mode", and your guests will be able to see the list of PR changes, as well as view/add comments. You can almost think of it as a turbo button for pull requests!  🏎️

![GitHub](https://user-images.githubusercontent.com/116461/59172651-1a5adf00-8afe-11e9-9646-1fa67e4dc8ba.gif)

<em>A Live Share guest (left) viewing the changes and comments in a pull request</em>

## Looking Forward

Hopefully this post illustrates how Live Share can complement your existing Git-based workflows, regardless if you want to collaborate on uncommitted code, get help with a tricky merge conflict, or perform a real-time code review (with or without a pull request). We've still got plenty of room for improvements (e.g. persisting code comments, edit-level user attributions), but we're already seeing teams have success using Git + Live Share together. Ultimately, our goal is to enable teams to **collaborate continuously**, by leveraging the asynchronous and synchronous workflows that work best for them.