How to avoid giving user credentials for every git push

In this blog post, learn different ways to save user credentials for the git push command.

How to do push changes without authentication every time to Github

As you know, whenever you are pushing the changes to GitHub, You need to authenticate to GitHub with a username and password.

Sometimes you want multiple commits without authentication, there is a process to do it.

git-credential-store and git-credential-cache are the commands to store the user credentials on the hard disk.

It contains only file system permission.

git-credential-store example

This command uses to save credentials stored in a local store. These credentials are saved indefinitely.


$ git config credential.helper cache
$ git push http://github.com/repository.git
Username:
Password:
[next time onwards, entering user details are not required]
$ git push http://github.com/repository.git
[credentials are not required to enter again, ]

Disable the store:


git config --unset credential.helper

git-credential-cache example

These are stored in a local cache. These save the credentials for a specific period.


$ git config credential.helper cache
$ git push http://github.com/repository.git
Username:
Password:
[next time onwards, entering user details are not required]
$ git push http://github.com/repository.git
[credentials are not required to enter again, ]

It enables and stores the credential into the file system cache for a default of 15 minutes Enable the store for a duration of time If you want to store the credentials for the duration of some time. The below timeout is 50 minutes.

git config --global credential.helper 'store --timeout=3000'

The disadvantage of this approach is user credentials are stored as plain text and not secured way. Another way is to use SSH with public and private keys added to Github.