Insert username and password into git-remote url before git push

I wrote a small script that is a wrapper around git push. It modifies the
git remote url to insert username and password (read from env). No need to store ssh keys on remote server or git clone with https credentials! If not credential are found, it throws an exception. You should only use it when you need to read the credentials from environment variables.

For github.com repo, It looks for GITHUB_USER first, then for GIT_USER,
and then USER environment variable. Similarly it looks for GITHUB_TOKEN, GIT_TOKEN for tokens. Fot gitlab.com repo, it looks for GITLAB_USER or GIT_USER or USER for username, and GITLAB_TOKEN, GIT_TOKEN for password.

If the script can’t determine the username and password, it raises an exception.

Then it calls git push on new url that has username and password. For example git push https://github.com/dilawar/Scripts will become git push https://dilawar:mytoken@github.com/dilawar/Scritps.

You can download the script from here.

Permalink at the time of writing: https://github.com/dilawar/Scripts/blob/33e735c7c92f77ac69b464b0b99fab9ee2668b65/,git_push


Leave a Reply