added documentation on storing credentials (#61660)

Co-authored-by: Jagpreet Grewal <jsg25@sfu.ca>
Co-authored-by: Roshan Jossy <roshanjossey@gmail.com>
This commit is contained in:
jg1111 2023-05-13 15:32:23 -07:00 committed by GitHub
parent 161a614fbe
commit 1192ec3908
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 1 deletions

View File

@ -1063,6 +1063,7 @@
- [ctran](https://github.com/ctran414)
- [Xeplon](https://github.com/Xeplon)
- [koanuywg](https://github.com/koanuywg)
- [Jagpreet Grewal](https://github.com/JagpreetGrewal)
- [danesusername](https://github.com/danesusername)
- [Rajat Bhosale](https://github.com/RajatBhosale)
- [Charandeep Singh](https://github.com/charandeepsinghb)

View File

@ -46,4 +46,7 @@ This document provides information about how to undo a commit on your local repo
This document is dedicated to all the tips and tricks websites, blog posts, and helpful sites that make our lives easier. They are a great reference to serve all of our needs, be it a beginner or an expert. This page should act as an index of all those useful links that would help everybody who is new in the open-source domain or someone who wants to learn more.
### [Creating a .gitignore file](creating-a-gitignore-file.md)
This document explains what a .gitignore file does, why to use it and how to create a .gitignore file. This file is used in almost all git projects. It helps commit only the necessary files to git.
This document explains what a .gitignore file does, why to use it and how to create a .gitignore file. This file is used in almost all git projects. It helps commit only necessary files to git.
### [Storing Credentials](storing-credentials.md)
This document explains how to store your credentials for repositories. This can be a security concern, so please follow the security policies of your place of work/study.

View File

@ -0,0 +1,48 @@
# Storing Credentials
You might have complained about this before - entering your username and password each time you access the repository can be a hassle and can interrupt your workflow if it takes too long. But it doesn't need to be that way.
We will be covering one of the methods available to us - [git credential cache](https://git-scm.com/docs/git-credential-cache).
**Note:** Please follow the security policies of your place of work/study.
## Caching
We can use git credential cache to store our username and password.
**Attention:** This method saves the credentials in *plaintext* on your PC's disk. Everyone on your computer can access it, e.g. malicious NPM modules.
### Global Credential Cache
If we wish to, we can store the credentials for every repository we are working with using one simple command:
```
$ git config --global credential.helper cache
```
**Reminder:** Please follow the security policies of your place of work/study.
### Repository Credential Cache
We can store the credentials for the repository we are working with using one simple command, similar to before:
```
$ git config credential.helper cache
```
**Reminder:** Please follow the security policies of your place of work/study.
### Cache Timeout
If we do not specify a length of time to store our credentials, they can potentially be stored forever. However, we can determine how long they will be kept in memory using this command:
```
git config credential.helper 'cache --timeout=<timeout>'
```
Using the helper, the credentials will never touch the disk and will be erased after the specified timeout. The default value is 900 seconds (15 minutes).
#### References
[Stack Overflow](https://stackoverflow.com/questions/35942754/how-can-i-save-username-and-password-in-git)
### [Additional Material](additional-material.md)