#!/bin/bash save-git-folder() { echo "Saving git commit hashes as 'commit' in .gitmodules." local git_folders=$(ls-git-folder .) for git_folder in $git_folders; do local commit_hash=$(git -C "$git_folder" rev-parse HEAD 2>/dev/null) if [[ -z "$commit_hash" ]]; then echo "Could not get commit for $git_folder" continue fi local submodule_name="$git_folder" git config -f .gitmodules submodule."$submodule_name".commit "$commit_hash" echo "Set commit for $submodule_name: $commit_hash" done echo "All submodule commits saved to .gitmodules." } sgf() { save-git-folder "$@" }