Skip to content

Instantly share code, notes, and snippets.

@alexrios
Created November 23, 2025 18:33
Show Gist options
  • Select an option

  • Save alexrios/a98a3eda1b282187e713ef0da9c98f44 to your computer and use it in GitHub Desktop.

Select an option

Save alexrios/a98a3eda1b282187e713ef0da9c98f44 to your computer and use it in GitHub Desktop.
Signing Git commits and tags with SSH - fish edition (based on: https://carlosbecker.com/posts/git-ssh-signing/)
function setup_git_signing -d "Configures Git to use SSH keys for signing commits"
set -l ssh_key_path ~/.ssh/id_ed25519.pub
set -l allowed_signers_file ~/.ssh/allowed_signers
# 1. Check if the public key exists
if not test -f $ssh_key_path
echo "Error: Public key not found at $ssh_key_path"
return 1
end
# 2. Get the email from git config
set -l git_email (git config --get user.email)
if test -z "$git_email"
echo "Error: Git user.email is not set. Please run 'git config --global user.email [email protected]' first."
return 1
end
echo "Configuring Git to use SSH signing..."
# 3. Set GPG format to SSH
git config --global gpg.format ssh
# 4. Set the signing key
git config --global user.signingkey $ssh_key_path
# 5. Create/Update the allowed_signers file
# We use a temporary variable to hold the new entry to avoid complex quoting issues
set -l new_entry "$git_email namespaces=\"git\" "(cat $ssh_key_path)
# Check if this entry already exists to avoid duplicates (optional but cleaner)
if not grep -qF "$new_entry" $allowed_signers_file 2>/dev/null
echo $new_entry >> $allowed_signers_file
echo "Added key to $allowed_signers_file"
else
echo "Key already exists in $allowed_signers_file"
end
# 6. Tell Git where the allowedSignersFile is
git config --global gpg.ssh.allowedSignersFile $allowed_signers_file
# 7. Enable auto-signing
git config --global commit.gpgsign true
git config --global tag.gpgsign true
git config --global format.signoff true
echo "Git SSH signing configuration complete! 🚀"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment