How to add or remove cached git credentials on linux server (Ubuntu)

This is something I need to do occasionally, that is, to add or remove cached git credentials on a Linux server. To add when you need to set up a git repository for a new project on new server for example.

How to add or remove cached git credentials on linux server (Ubuntu)

For pulling or cloning from a private git repository you need to use your github access token which has an expiry date, so if your access token is regenerated you need to update your password/access token on server to allow pull/push for your git repository. For this purpose you may need to remove your cached git credentials so that the new one can be cached.

Method to add or use cached git credentials

So whenever I need to add/store credentials I would do:

git config credential.helper store

Next time, when I do my first pull or push and enter my credentials it would store my git credentials in credential helper so next time I won’t have to enter them again. This goes until my github access token is regenerated for some reason.

So if you get your access token changed you an go back to the server console and run:

git config --global --unset credential.helper

Once done, next time when you run a pull push command it will prompt you to enter user name and your new password/access token. Once validated it will be stored until your next lifetime of the access token.

I hope this simple tutorial to add and remove cached git credentials helps you!

Leave a Reply