Skip to content

Instantly share code, notes, and snippets.

@disouzam
Created January 14, 2026 18:49
Show Gist options
  • Select an option

  • Save disouzam/1ddef9c33f3704fcc873f7d868d742de to your computer and use it in GitHub Desktop.

Select an option

Save disouzam/1ddef9c33f3704fcc873f7d868d742de to your computer and use it in GitHub Desktop.
Script to use for tutorial purposes on Git
#!/bin/bash
# A script to inspect the current Git repository status and display relevant information.
file_name="files-in-git"
old_file="${file_name}_old.txt"
new_file="${file_name}.txt"
function generate_git_file_list() {
ls -1 -R .git > $1
}
if [ -f "$new_file" ] && [ ! -f "$old_file" ]; then
mv "$new_file" "$old_file"
echo "File renamed from $new_file to $old_file"
elif [ ! -f "$new_file" ]; then
echo "File $new_file does not exist"
generate_git_file_list "$old_file"
fi
generate_git_file_list "$new_file"
git diff --no-index "$old_file" "$new_file"
@disouzam
Copy link
Author

Usage:

  • Add this script in root folder of a git repo (i.e., if you use ls --all, you should see .git folder in the listing in top folder)
  • Open a shell in root folder
  • Type the command below
watch -n 5 bash inspect-git.sh

Side effect: two text files in your repo (files-in-git.txt and files-in-git_old.txt).
Script can be edited to add these files to .gitignore

@disouzam
Copy link
Author

disouzam commented Jan 14, 2026

Inspired on John Britton's presentation at https://www.youtube.com/watch?v=lG90LZotrpo&t=7s, entitled
Git Internals by John Britton of GitHub - CS50 Tech Talk

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