Read Anthropic’s case study about Graphite Reviewer

Using GitHub Gists to share code review snippets

Sara Verdi
Sara Verdi
Graphite software engineer
Try Graphite

GitHub Gists are a versatile tool for sharing code snippets, configurations, and other text-based content. By using GitHub Gists in code reviews, developers can facilitate collaboration, highlight specific issues, and provide reusable solutions. This guide explores how to use GitHub Gists for code reviews, including examples and integration with tools like Graphite's PR inbox.

GitHub Gists streamline code reviews by isolating code snippets into shareable, syntax-highlighted formats. Their version control ensures transparency, while reusable snippets save time for recurring feedback. With both public and private sharing, Gists fit open-source and team-specific needs. GitHub Gists are particularly effective for code reviews because they:

  • Allow quick sharing of code snippets, reducing clutter in pull request comments.
  • Support syntax highlighting, making code easier to read and understand.
  • Provide a versioned and persistent record of shared snippets.
  • Enable public or private sharing depending on the review's scope.

When combined with the Graphite PR inbox, which organizes pull requests for seamless management, GitHub Gists can improve review workflows. The inbox categorizes pull requests into actionable sections such as "Needs your review" or "Waiting for review," enabling developers to prioritize their tasks effectively. When Gists are used within this structure, reviewers can provide detailed, reusable code suggestions or highlight specific issues with clarity and precision.

The Graphite PR inbox also helps track the lifecycle of feedback shared through Gists. For instance, by using the "Returned to you" section, reviewers can monitor updates to pull requests that address the issues linked in their Gists. This integration minimizes clutter in comments, maintains a clear history of shared feedback, and fosters a more efficient, collaborative review process. Together, the PR inbox and Gists create a workflow that is both structured and adaptable, ensuring that no critical feedback is overlooked.

  1. Create a new Gist:

    • Navigate to GitHub Gists.
    • Click "New Gist."
    • Add a descriptive filename with an appropriate extension (e.g., review-feedback.js).
    • Paste your code snippet into the editor and add optional comments.
  2. Choose visibility:

    • Public for open-source projects or wide team sharing.
    • Secret for internal reviews.
  3. Save and share:

    • Click "Create secret gist" or "Create public gist."
    • Copy the URL and share it in pull request comments.

To add a Gist to a pull request comment:

  1. Copy the Gist URL.
  2. In the pull request discussion, paste the URL with context. For example:

    "Please refer to this Gist for an optimized version of the function."

GitHub automatically embeds the Gist in the comment, displaying the code with syntax highlighting.

The Graphite PR inbox organizes pull requests into specific sections, and when reviewing PRs in the inbox, you can use Gists to share detailed suggestions while keeping discussions concise. For example, create a "Returned to you" section filter to track PRs that require updates based on Gist feedback.

  • Collaborating on Gists: Gists support inline comments for collaboration. Share the Gist URL and request team members to comment directly on the lines of code.
  • Version control: Every update to a Gist creates a new version. Use the version history to track changes suggested during the review.
  • Embedding Gists: Embed Gists in documentation or other GitHub issues to provide additional context.
  • Using Gists for templates: Create reusable templates for common feedback, such as code style guidelines or API contracts, and share them in reviews.
  1. Identify a pull request: Open the Graphite PR inbox and locate a pull request that requires review under the "Needs your review" section.

  2. Provide feedback with Gists: If the PR contains a problematic code segment, create a Gist with a revised version or additional context.

  3. Share the Gist in comments: Add the Gist link to the pull request discussion, explaining its purpose.

  4. Track updates: Use the "Returned to you" section in the PR inbox to monitor the pull request until the contributor addresses the Gist feedback.

GitHub Gists are an excellent complement to code reviews, enabling clear, reusable, and collaborative feedback. When paired with tools like the Graphite PR inbox, they streamline the review process and enhance collaboration.

Built for the world's fastest engineering teams, now available for everyone