Avoid Entering Git Credentials for Every Push/Pull by Embedding Them in the Repo URL

It’s possible to embed credentials in the Git repo URL. If a URL with embedded credentials is used to clone a repo, Git won’t prompt for credentials on any subsequent push/pull operations on this repo.

A repo URL with embedded credentials looks like this:

https://username:password@git-codecommit.us-east-1.amazonaws.com/v1/repos/my-repo

Use it when you clone the repo & you never have to enter the credentials again.

But there’s a catch! The credentials must be URL encoded.

Consider the following Git credentials that AWS IAM generated for my IAM user:

harishkm+1-at-123456789012
fU/mk96usvV41JAnCJH2LZKIY+gTl92iI859g6M37Mo=

They contain special characters which aren’t valid for a URL. They must be URL encoded before embedding them. The quickest way to URL encode a string is to run the encodeURIComponent() JS function in Chrome console:

The encoded credentials can now be embedded in a repo URL:

harishkm%2B1-at-123456789012
fU%2Fmk96usvV41JAnCJH2LZKIY%2BgTl92iI859g6M37Mo%3D

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.