Python script: RSS feed from Git commit log

The Python script below creates an RSS file from a git commit log. I'm using an expanded version of this script to generate the RSS feed for my site. It can be used as a starting template or demo of the GitPython and feedgen modules. Although the script is runnable the resulting RSS file is only useful as sample output.

To use the script the following modules must be installed:

  • GitPython
  • feedgen



  • The code used in the feed creation function is taken directly from the Python feedgeen Create a Feed example.
  • RSS and Atom feed items are intended to point to individual web pages which this script doesn't create. If you want useful item links you'll need to generate the target pages or create logic that maps commits to your desired target pages.
  • This code has only been tested in one feed reader. If the description doesn't look correct in your feed reader you may need to place the description text in a CDATA block.
  • To leverage the automation check out Conventional Commits. It's a convention for wording commit messages that, among many things, makes it easier writing automation tools for processing the messages.

The Script

#!/usr/bin/env python3

from feedgen.feed import FeedGenerator
from git import Repo

repo_directory = '.'
repo_branch = 'main'
num_feed_items = 20

def create_feed():
    feed = FeedGenerator()'')
    feed.title('Some Testfeed'){'name': 'John Doe', 'email': ''})'', rel='alternate')
    feed.subtitle('This is a cool feed!')'', rel='self')
    return feed

def main():
    repo = Repo(repo_directory)
    rss_feed = create_feed()
    for commit in list(repo.iter_commits(repo_branch, max_count=num_feed_items)):
        feed_item = rss_feed.add_entry()
        feed_item.description(commit.message.replace('\n', '<br>\n')){'href': '' + commit.hexsha})

if __name__ == "__main__":