Sometimes when you SSH into a machine and reattach your tmux session you’ll find that your SSH environment variable is stale so commands like “git pull” don’t work. Here’s a simple command that refreshes that variable. I simply type “r” anytime I notice my session is stale or a command requiring ssh authentication fails:

# used to refresh ssh connection for tmux 
# http://justinchouinard.com/blog/2010/04/10/fix-stale-ssh-environment-variables-in-gnu-screen-and-tmux/                                                                                                                                                                                         
function r() {   
  if [[ -n $TMUX ]]; then
    NEW_SSH_AUTH_SOCK=`tmux showenv|grep ^SSH_AUTH_SOCK|cut -d = -f 2`
    if [[ -n $NEW_SSH_AUTH_SOCK ]] && [[ -S $NEW_SSH_AUTH_SOCK ]]; then 
      SSH_AUTH_SOCK=$NEW_SSH_AUTH_SOCK  
    fi
  fi
}


I can’t take credit for this wonderful tidbit, it was written by Eivind Uggedal in a comment in this post.