Git Bash is a command-line interface for Windows that combines Git with Bash, a Unix shell. It allows Windows users to execute Git commands and Unix-like shell commands in a familiar environment. This tool is particularly useful for developers who prefer a Unix-style command-line experience on Windows systems.
Before you begin, ensure you have the following:
- Git Bash installed on your Windows system.
- A GitHub account.
- Optional: Graphite CLI installed for enhanced Git workflows.
Step 1: Generate an ssh key pair
Open Git Bash.
Enter the following command, replacing your email address:
Terminalssh-keygen -t ed25519 -C "your_email@example.com"If your system doesn't support Ed25519, use RSA:
Terminalssh-keygen -t rsa -b 4096 -C "your_email@example.com"When prompted to "Enter a file in which to save the key," press Enter to accept the default location (
/c/Users/your_user/.ssh/id_ed25519
).At the prompt to enter a passphrase, you can choose to enter one for added security or leave it empty for convenience.
Step 2: Add your SSH key to the SSH agent
Start the SSH agent in the background:
Terminaleval "$(ssh-agent -s)"Add your SSH private key to the agent:
Terminalssh-add ~/.ssh/id_ed25519
Step 3: Add your SSH key to your GitHub account
Copy the SSH public key to your clipboard:
Terminalclip < ~/.ssh/id_ed25519.pubLog in to your GitHub account.
Navigate to "Settings" > "SSH and GPG keys".
Click "New SSH key", provide a descriptive title, paste your key into the "Key" field, and click "Add SSH key".
Step 4: Test your SSH connection
To verify that your SSH key is correctly configured:
ssh -T [email protected]
You should see a message like:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Step 5: Configure Git to use SSH
Ensure that your Git operations use SSH instead of HTTPS:
Check your current remote URL:
Terminalgit remote -vIf the URL starts with
https://
, change it to SSH:Terminalgit remote set-url origin git@github.com:username/repository.gitReplace
username
andrepository
with your GitHub username and repository name, respectively.
Step 6: Integrate SSH keys with Graphite
If you're using Graphite to manage your Git workflows, ensure it utilizes your SSH configuration:
Open Git Bash and run:
Terminalgt configIn the interactive menu, configure the following:
- Git remote name: Ensure it matches your SSH-configured remote (usually
origin
). - GitHub repository information: Verify that Graphite correctly infers your repository name and owner from the SSH URL.
- Git remote name: Ensure it matches your SSH-configured remote (usually
For more detailed configuration options, refer to Graphite's CLI documentation.
Troubleshooting Tips
- Permission denied (publickey): Ensure your SSH key is added to the SSH agent and associated with your GitHub account.
- Host key verification failed: You might need to add GitHub to your known hosts by attempting to SSH into GitHub and accepting the prompt.
- Multiple SSH keys: If you use multiple SSH keys, create a
~/.ssh/config
file to specify which key to use for each host.
Conclusion
By following these steps, you've set up SSH keys with Git Bash, enhancing the security and convenience of your Git operations. Integrating these keys with Graphite further streamlines your development workflow.