askvity

How Do I Add Shields to GitHub Readme?

Published in GitHub Readme Badges 3 mins read

To add shields or badges to your GitHub README, you typically use a service like Shields.io to generate the appropriate code and then paste that code directly into your README file.

Adding shields is a popular way to display dynamic or static information about your project, such as build status, version number, license type, or follower count, directly in your repository's documentation. This provides a quick visual summary for visitors.

Getting Started: The Simple Steps

Adding a shield is a straightforward process, broken down into these key steps:

  1. Choose Your Badge Source: Go to a website specifically designed for generating README badges. The most popular and versatile is Shields.io. This site offers a vast array of predefined badges and allows for custom ones.
  2. Select and Customize Your Badge:
    • Browse or search for the type of badge you want (e.g., build status, license, version, contributors).
    • Click on the specific badge you're interested in.
    • You will typically be presented with options to customize the badge, such as changing the text, color, or linking it to specific data (like a build pipeline).
  3. Copy the Markdown Code: Shields.io and similar services provide the code for the badge in various formats. For a GitHub README, you'll want the Markdown format. Copy the generated Markdown code. This code usually looks something like ![Badge Text](Image URL).
  4. Add to Your README:
    • Open the README.md file in your GitHub repository. You can do this directly on GitHub's website by clicking the edit button or by editing the file locally and pushing the changes.
    • Paste the copied Markdown code into the location in your README where you want the badge to appear. Common locations include the top of the file, below the main title, or in a dedicated "Badges" section.
    • Save your changes.

Once saved, GitHub will render the Markdown, and the badge image will be displayed in your README.

Why Add Shields?

  • Visual Appeal: Shields make your README look more professional and informative at a glance.
  • Quick Information: They provide immediate status updates (like passing tests or current version) without needing to dig into files.
  • Trust & Credibility: Displaying things like test coverage or license information builds confidence in your project.

Example of Markdown Code

Here's an example of what the Markdown code for a simple badge might look like:

![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg)

When GitHub renders this Markdown, it fetches the image from the provided URL (https://img.shields.io/...) and displays it.

Common Badge Types

While Shields.io offers extensive options, here are some frequently used badge categories:

Category Example Use Case
Build Status Show if your continuous integration build passed
Version Display the current release or package version
License Indicate the project's open-source license (e.g., MIT)
Activity Show last commit date or number of contributors
Social Display Twitter followers or GitHub stars

By following these steps, you can easily enhance your GitHub README with informative and attractive shields.

Related Articles