karlkurzer karlkurzer - 1 year ago 86
Git Question

set git user name and email after ssh login on remote with one local user

I would like to do the following, which works with the

flag, however I need to do it on an on session basis, as more than one person might be working on the remote machine at a time, and hence it is important that the commits are annotated with the correct name.

ssh root@host -t "git config --ONLY_FOR_CURRENT_SESSION user.name 'Max Payne'; git config --ONLY_FOR_CURRENT_SESSION user.email 'max@payne.com'; bash"

so basically I want to:

  1. use ssh to login to remote machine

  2. pass a command that will set my git user.name and user.email for the current session

Answer Source

If you can ssh in to the machine, you can also clone the repository and simply work locally, and that is usually the way to go.

That said, if you insist on working this way, you can, rather than setting up configuration files (which are necessarily shared between separate sessions, since the file system itself is also shared between separate sessions), set numerous environment variables as described in the top-level git documentation. These include GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_COMMITTER_NAME, and GIT_COMMITTER_EMAIL, which are further described in the git commit-tree documentation.

Environment variables are inherited from parent processes to child processes. They do not cross the boundary in the other direction, i.e., no child process can affect its parent's environment data. For this reason all environment-setting commands are (must be) built in to the shell.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download