Every day, millions of developers collaborate using one of the most fundamental tools in software: Git. As a distributed version control system (DVCS), Git enables you to work with a personal, offline copy of a codebase, and when ready, carefully merge your changes into a hosted repository that's shared amongst the team. This supports an extremely flexible form of asynchronous collaboration, 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: to provide a real-time complement for Git.
In a previous post, I illustrated how Live Share enables a unique form of collaboration, for a diverse set of developer use cases. 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!
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. 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) 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 🚀
A Live Share guest (left) viewing and discarding changes directly in their editor
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 🔥
A Live Share guest (left) communicating with the host (right) via code comments
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 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, and therefore, if a guest has it installed, they can explore project history just as if they were working against a local repository.
A Live Share guest (left) using the GitLens extension to navigate a file's history
When you're collaboratively editing a file in a Live Share session, updates are synchronized in real-time using an algorithm called operational transforms. 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.
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, you can choose to handle the conflicts one-by-one, or divide-and-conquer them. It's completely up to you!
A Live Share guest (left) collaboratively resolving a merge conflict in real-time
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 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! 🏎️
A Live Share guest (left) viewing the changes and comments in a pull request
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.