Git Credential Basics
What are Git Credentials?
Git credentials are authentication mechanisms that allow you to securely interact with remote repositories. They help verify your identity when pushing, pulling, or performing other remote operations.
Types of Git Credentials
1. HTTPS Credentials
When using HTTPS, Git requires username and password or personal access token for authentication.
## Example of HTTPS repository clone
git clone https://github.com/username/repository.git
2. SSH Credentials
SSH uses cryptographic key pairs for secure authentication without repeatedly entering passwords.
## Generate SSH key
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Credential Storage Methods
Method |
Description |
Pros |
Cons |
Cache |
Temporary memory storage |
Quick access |
Short-lived |
Store |
Persistent file storage |
Convenient |
Potentially less secure |
Manager |
System-level credential management |
Secure |
Platform-specific |
Credential Helper Configuration
## Set credential helper
git config --global credential.helper store
git config --global credential.helper cache
Authentication Flow
graph TD
A[User] --> B{Authentication Method}
B --> |HTTPS| C[Enter Username/Password]
B --> |SSH| D[Use SSH Key]
C --> E[Credential Stored]
D --> E
Best Practices
- Use personal access tokens instead of passwords
- Enable two-factor authentication
- Regularly rotate credentials
- Use SSH keys for enhanced security
By understanding Git credentials, you can securely manage your repository interactions with LabEx's recommended practices.