Post

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:

  1. Windows:

    • Download the installer from git-scm.com.
    • Run the installer and follow the prompts.
  2. macOS:

    • Git should be pre-installed. If not, you can install it via Homebrew:
      1
      
      brew install git
      
  3. Linux (Debian/Ubuntu):

    • Install Git via apt:
      1
      
      sudo apt install git
      

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:

  1. Go to github.com in your web browser.
  2. Click on “Sign up” and follow the instructions to create your account.

Setting up a Repository

To create a new repository on GitHub:

  1. Log in to your GitHub account.
  2. Click on the “+” icon in the top-right corner and select “New repository.”
  3. Fill in the repository name, description, and choose visibility settings.
  4. 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

  1. Export your GPG key:

    1
    
    gpg --armor --export <key_id>
    
  2. Copy the GPG key output.

  3. Go to your GitHub account settings.

  4. Click on “SSH and GPG keys” in the left sidebar.

  5. Click “New GPG key” and paste your key.

  6. Click “Add GPG key.”

Verifying Commits

To sign your commits with your GPG key:

  1. Set your GPG key for signing:

    1
    
    git config --global user.signingkey <key_id>
    
  2. 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! 🚀

This post is licensed under CC BY 4.0 by the author.

Trending Tags