Reference library

Git + Python

Automate Git from Python — diffs, hooks, release tags, and repo housekeeping.

26 matches
Git + Python medium

Python Script to Rotate a Leaked API Key

A checklist-driven Python script that scans a codebase for a leaked API key, replaces it with a new one, and prints a step-by-step rotation checklist.

security secrets file-scanning
Python
#!/usr/bin/env python3
"""Checklist for rotating a leaked API key across a codebase."""

import re
from pathlib import Path


CHECKLIST = [
    "Identify all files containing the leaked key",
    "Generate a new key with sufficient entropy",
    "Update the secret storage/CI environment variables",
    "Replace the ol…
14 0 Open
Git + Python medium

Show Blame Line Author with subprocess in Python

This Python script runs git blame --line-porcelain via subprocess and counts how many lines each author owns in a file.

git subprocess blame
Python
import subprocess
from collections import Counter

def get_blame_authors(file_path):
    """Extract author names from git blame output using subprocess."""
    result = subprocess.run(
        ["git", "blame", "--line-porcelain", file_path],
        capture_output=True,
        text=True,
        check=True,
    )
   …
11 0 Open

Browse by section

Each section groups closely related Python snippets.

Git + Python — Python code examples

What you will find here

This page collects git + python snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.