Connect Github Account To Git Using GPG Key
Git is a distributed version control system used to track changes in source code during software development. It allows multiple developers to collaborate on projects efficiently.
Installation
To install Git, follow these steps:
Windows:
- Download the installer from git-scm.com.
- Run the installer and follow the prompts.
macOS:
- Git should be pre-installed. If not, you can install it via Homebrew:
1
brew install git
- Git should be pre-installed. If not, you can install it via Homebrew:
Linux (Debian/Ubuntu):
- Install Git via apt:
1
sudo apt install git
- Install Git via apt:
Configuration
After installing Git, configure your username and email:
1
2
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Introduction to GitHub
GitHub is a platform that hosts Git repositories and facilitates collaboration among developers. It offers features like pull requests, issue tracking, and project management.
Creating a GitHub Account
To create a GitHub account:
- Go to github.com in your web browser.
- Click on “Sign up” and follow the instructions to create your account.
Setting up a Repository
To create a new repository on GitHub:
- Log in to your GitHub account.
- Click on the “+” icon in the top-right corner and select “New repository.”
- Fill in the repository name, description, and choose visibility settings.
- Click “Create repository.”
Cloning a Repository
To clone a repository from GitHub to your local machine:
1
git clone <repository_url>
Setting Up GPG Key with GitHub
Using GPG (GNU Privacy Guard) keys adds an extra layer of security to your commits by verifying your identity.
Generating a GPG Key
To generate a GPG key:
1
gpg --full-generate-key
Follow the prompts to set up your key, including selecting the key type and key size, and providing your name and email.
Adding the GPG Key to GitHub
Export your GPG key:
1
gpg --armor --export <key_id>
Copy the GPG key output.
Go to your GitHub account settings.
Click on “SSH and GPG keys” in the left sidebar.
Click “New GPG key” and paste your key.
Click “Add GPG key.”
Verifying Commits
To sign your commits with your GPG key:
Set your GPG key for signing:
1
git config --global user.signingkey <key_id>
Enable commit signing:
1
git config --global commit.gpgsign true
Now, when you commit changes, they will be signed with your GPG key.
Conclusion
You’ve now learned the basics of Git, GitHub, and setting up GPG key for signing commits. Happy coding! 🚀