Last Updated: February 25, 2016
·
1.701K
· jabbrwcky

Git credentials on the go

Tired of having to add your author info to every commit and to retype your credentials when you work on remote (eventually shared) box?
Just take your credentials with you!

What you need:

  1. Configure your git author/committer info via environment variables
  2. Have a remote box with an sshd that is configured to accept your GIT_* environment variables in /etc/ssh/sshd_config ( Maybe you'll have to ask your admin nicely for this one )
  3. Connect to the box using ssh-agent and Agent-Forwarding

Set your git info in your env

Add this to your .bashrc (or to vour ~/.secrets if using YADR):

export GIT_AUTHOR_NAME="Jens Hausherr"
export GIT_AUTHOR_EMAIL="mail@example.com"
export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"

SSHD configuration

Configure the remote SSHD to accept you environment variables:

AcceptEnv LANG LC_* GIT_*

SSH client

Fire up your ssh-agent and add your key via ssh-add.
Connect to the remote box using Agent-Forwarding

ssh -A user@host    #for Linux/Mac

If everything worked you should find the GIT_* variables in the shell of the remote box along with the SSH_AUTH_SOCK that forwards your auth key via the SSH connection.

Happy remote committing :)