Configuring Git Hooks with GitHub Authentication Tokens

Last updated: July 14, 2025

When setting up Git hooks to authenticate with GitHub using tokens, proper string quoting is essential to ensure the command executes correctly. This is particularly important when configuring hooks that use environment variables.

Correct Hook Configuration

Use single quotes around the Git configuration command when setting up GitHub token authentication in hooks. Here's the correct format:

git config --global url.'https://${GITHUB_TOKEN}@github.com'.insteadOf 'https://github.com'

This hook can be configured in three ways:

  • Through the web interface

  • In your Terraform configuration

  • In the repository's .spacelift.config.yml file

Setting up the GitHub Token

The GITHUB_TOKEN should be defined either:

Troubleshooting

If you see an error like the following, it typically indicates incorrect quote handling:

fatal: could not read Password for 'https://%[24%7BGITHUB_TOKEN%7D@github.com': No such device or address

To verify your configuration is working correctly, you can run this command as a task:

git config --global --get-regexp '^url\.'