Effective Code Collaboration with Bitbucket Snippets

George Vulov
Mohami Blog
Published in
6 min readAug 18, 2020

Sharing and collaborating on code is a crucial capability for professional software teams. Whether it’s to support a teaching moment with a junior programmer, or maybe to get a little one-off input from a guru outside the team, it’s often appropriate to share very specific blocks of code without exposing every line in a file.

The Bitbucket Code Snippets macro helps you more effectively share and track user-defined chunks of source code, while maintaining source control integrity in the Main branch. You can share chunks of code openly with the team or keep it private, for your eyes only. You can also embed any Bitbucket snippet directly in your Confluence pages.

Whether or not all the built-in functionality works for your requirements, Snippets offers an API that lets you automate Snippets functionality and make it part of your established development processes.

Why Use Code Snippets?

Source code is just text, so who needs a tool to share text? Anyone can manually cut and paste one-off code from your repository, but if you’re regularly sharing little code chunks in the wild, things can get out of hand quickly. It’s all too easy to lose track of changes if you skip rigorous protocols for ensuring the code remains in sync with source control.

Bitbucket Code Snippets is built on Git, so revisions are reliably tracked, and snippets can be cloned and pushed.

What is a Snippet Anyway?

Any user-defined, contiguous chunk of source code can be extracted from source control as a snippet. It’s any splice of code you want to share or take offline, without the constraints of file boundaries.

So how big is a chunk exactly? That’s your call — as big or as small as you need. Snippets can be a few lines of code to hundreds or thousands of lines. That means it can be anything from a small subsection of a single source file, or a chunk of code that crosses multiple files, that can then be managed as a single entity.

Bitbucket snippets can be entirely private, shared with a particular workspace, or shared openly with anyone in your workspace — you have full control of who can view and who can edit.

Plus, they’re easy to create — just drag and drop your code into a simple form, then select categories then security preferences. Syntax highlighting is built right in.

Create Bitbucket Code Snippet

Key Features

While the core functionality of Code Snippets for Bitbucket is to help you manage and share everything from small code segments to multiple files, that’s only possible thanks to its full set of supporting features.

Feature Highlights

  • Share your code snippets with other users
  • Store your code snippets in Bitbucket Server
  • Comment on snippets
  • Secure snippets with fine-grained visibility and access controls
  • Clone your snippet with a single click so you can work on it locally then push back up to Bitbucket Cloud
  • Discover and browse snippets created by other users
  • Star snippets to add them to your own snippets collection
  • Embed snippets on any website or in Confluence by using Mohami’s free Snippets for Confluence add-on
  • The API lets you extend your custom apps with full Snippets functionality

The Snippets UI

Users can create snippets just by pasting code or dragging files directly into the create page, and giving your snippet a name.

Syntax-sensitive design instantly highlights keywords and code structure. For collaborative coding, you can make any snippet entirely public with a few clicks.

Browse your own snippets, starred snippets, all in a selected category, or all available snippets in the system …

Bitbucket Snippets UI

Granular Permission Control

Permissions extend to both read and write privileges, and snippets can belong to a workspace or an individual. That means you can make your own completely private snippets, or allow others to just view but not edit, or open read and write access to the entire workspace.

Bitbucket Snippets Granular Permission Control

You can specify a particular workspace to create the snippet in, and members of that workspace can collaborate on the code, or just limit them to read only access.

Profile Integration

Integration with profile views lets you browse snippets by particular creators.

Bitbucket Snippets Profile Integration

Use Cases

With all the focus on features, we shouldn’t lose sight of what really matters — the actual practical use cases.

Experienced development managers know that the best way to go fast is not to cut corners, but to write solid, bug-free code. A big part of assuring that quality is sensible collaboration at all levels among developers.

Whether you’re in a regular release cadence, in continuous delivery mode, embracing waterfall, or still trying to transition to ‘real’ agile, you probably have to contend with the use cases below.

Limiting code duplication

Right after that sprint planning meeting, you realize you’ve already written some of the functions needed to complete someone else’s task. Maybe.

Nonetheless, it’s an opportunity to pull out the relevant snippets, share them with the assigned developer, and intercept any potential code duplication. Sharing and commenting on snippets can help overcome that natural resistance to using someone else’s code. Afterall, the DRY principle applies to teams as well as developers.

Mentoring and training

Senior programmers typically set aside some regular bandwidth to mentor newbies and junior programmers. Whether that consists of pair programming, code reviews, or an intelligent combination of the two, Code Snippets is a great way to comment on and share focused segments of source code.

Sharing across projects

Leveraging what’s already written between teams is, let’s face it, rarely done well. It’s a huge challenge both to discover and to then successfully share code between teams.

While making this practical requires discipline and a comprehensive strategy, some organizations have done it successfully. It takes far more than code sharing, but Snippets can be a useful tool in that effort, and a critical component of success.

Summary

Tight collaboration within the team, whether you’re trying to limit duplicated effort, promote pair-programming, or conducting regular code reviews, the ability to readily share key segments of source code is essential.

Snippets for Bitbucket is built to support superior quality — both better collaboration, and better code.

Try it or upgrade for free right now

Want to try Snippets for Bitbucket for free? Code Snippets and other powerful plugins from Mohami are available from the Atlassian Marketplace. Also, checkout Mohami’s free Snippets for Confluence add-on to embed Snippets in your Confluence pages.

Your Confluence administrator can start plugin installation with a single mouse click and you can experience the benefits of Code Snippets.

  1. Log into your Confluence instance as an admin and choose Add-ons, or go to the Atlassian Marketplace.
  2. Locate Snippets for Bitbucket Server and click Try it free.
  3. You’re all set! Click Close in the Installed and ready to go dialog.

Code Snippets supports server and data center deployments.

Mohami extends the Atlassian ecosphere with a suite of sensible, productivity-boosting macros that plug key gaps in functionality, unlock integration between platforms, and streamline development operations.

--

--