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