- Using SSH Keys (Recommended)
- Using Git Credential Helper
Method 1: Using SSH Keys (Recommended)
This is the most secure approach. It generates a cryptographic key pair on your machine and adds the public key to your Git hosting service.ssh-keygen -t ed25519 -C "[email protected]"
Then add it to your hosting service. For GitHub, follow the official guide.
git remote set-url origin [email protected]:<username>/<repository>.git
Method 2: Using Git Credential Helper
This method stores your credentials locally. It is less secure than SSH keys but simpler to set up.For a more secure credential storage option, consider using the Git Credential Manager (GCM):