Skip to content

Instantly share code, notes, and snippets.

@shrwnsan
Last active September 15, 2025 05:25
Show Gist options
  • Save shrwnsan/3937631 to your computer and use it in GitHub Desktop.
Save shrwnsan/3937631 to your computer and use it in GitHub Desktop.
This script is particularly useful for quickly checking the status and information of Git repositories without running multiple separate commands
#!/bin/bash
# Git Repository Information Script
#
# This bash script provides a comprehensive overview of a Git repository by
# combining multiple Git commands into a single, easy-to-read output.
#
# Features:
# - Shows current branch information
# - Displays remote repository details
# - Provides repository size and object count
# - Shows latest commit details with file changes
# - Lists all local branches
# - Supports specifying a repository path as an argument
# - Converts absolute paths to tilde notation for readability
# - Validates that the specified path is a Git repository
#
# Usage:
# git-info # Run in current directory
# git-info /path/to/repo # Run for a specific repository
#
# Installation:
# 1. Save the script as `git-info`
# 2. Make it executable: `chmod +x git-info`
# 3. Add to your PATH or move to a directory in your PATH (e.g., `/usr/local/bin` or `~/.local/bin`)
#
# Requirements:
# - Git must be installed and available in PATH
# - Bash shell
#
# This script is particularly useful for quickly checking the status and information
# of Git repositories without running multiple separate commands.
# Function to convert absolute path to tilde path if applicable
convert_to_tilde_path() {
local path="$1"
if [[ "$path" == "$HOME"/* ]]; then
echo "~${path#$HOME}"
else
echo "$path"
fi
}
# Determine the repository path (current directory if not specified)
REPO_PATH="${1:-$(pwd)}"
# Check if the path is a git repository
if ! git -C "$REPO_PATH" rev-parse --git-dir > /dev/null 2>&1; then
echo "Error: $REPO_PATH is not a git repository"
exit 1
fi
# Change to the repository directory
cd "$REPO_PATH" || exit 1
echo "=== Repository Information ==="
echo "Repository path: $(convert_to_tilde_path "$(pwd)")"
echo "Current branch: $(git rev-parse --abbrev-ref HEAD)"
echo ""
echo "=== Remote Information ==="
git remote -v
if [ $(git remote | wc -l) -eq 0 ]; then
echo "No remotes configured"
fi
echo ""
echo "=== Repository Size ==="
git count-objects -v
echo ""
echo "=== Latest Commit ==="
git show --stat
echo ""
echo "=== Branch Information ==="
echo "Local branches:"
git branch
echo ""
echo "=== Repository Config ==="
cat .git/config
echo ""
@shrwnsan
Copy link
Author

Write-up via my blog post @ http://j.mp/sv5ZMx (Just a Memo)

@shrwnsan
Copy link
Author

Updated with a modern version (Sept 2025) that can live in ~/.local/bin (or ~/bin)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment