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 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 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 will become git push

You can download the script from here.

Permalink at the time of writing:,git_push

Leave a Reply