Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save muath-ye/a743c91047bb5b54255d8057e63bcd2c to your computer and use it in GitHub Desktop.
Save muath-ye/a743c91047bb5b54255d8057e63bcd2c to your computer and use it in GitHub Desktop.

How to Sign Your GitHub Commits with GPG for the Verified Badge

If you want your GitHub commits to show the green Verified badge, you need to sign your commits cryptographically with GPG. This article will guide you through generating a GPG key, adding it to GitHub, and configuring Git to sign your commits automatically.


Step 1: Generate a GPG Key

Open your terminal and run:

gpg --full-generate-key
  • Choose the default key type (RSA and RSA).
  • Use a key size of 4096 bits for strong encryption.
  • Set the key to never expire or choose an expiration date.
  • Enter your name and the email address linked to your GitHub account.
  • Optionally, set a passphrase to protect your key.

Step 2: Find Your GPG Key ID

After generating your key, list your secret keys with their IDs by running:

gpg --list-secret-keys --keyid-format LONG

You will see an output like this:

/home/user/.gnupg/secring.gpg
------------------------------
sec   rsa4096/53342B0F19EC835B 2025-05-20 [SC]
      1234ABCD5678EF90ABCDEF1234567890ABCDEF12
uid           [ultimate] Your Name <[email protected]>

Copy the long key ID after the slash (/). In this example, it is:

53342B0F19EC835B

Step 3: Export Your Public GPG Key

Next, export your public key in ASCII format so you can add it to GitHub:

gpg --armor --export 53342B0F19EC835B

This command outputs a block of text starting with:

-----BEGIN PGP PUBLIC KEY BLOCK-----
...
-----END PGP PUBLIC KEY BLOCK-----

Copy the entire output.


Step 4: Add Your GPG Key to GitHub

  1. Go to GitHub Settings → SSH and GPG keys.
  2. Click New GPG key.
  3. Paste the copied public key into the text box.
  4. Click Add GPG key to save.

Step 5: Configure Git to Use Your GPG Key

Tell Git to use your GPG key for signing commits by running:

git config --global user.signingkey 53342B0F19EC835B

Enable commit signing by default:

git config --global commit.gpgsign true

Step 6: Create Signed Commits

Now, when you create commits, Git will sign them automatically.

git commit -m "Your commit message"

Or explicitly sign a commit:

git commit -S -m "Your commit message"

Step 7: Push and Verify

Push your commits to GitHub:

git push

Check your commit on GitHub — it should show a green Verified badge next to your commit message!


Summary

By generating a GPG key, adding it to GitHub, and configuring Git, you prove that your commits are genuinely from you. This increases your project's security and trustworthiness.


If you want, I can help you with troubleshooting or setting this up on your OS! Just ask.

@muath-ye
Copy link
Author

كيفية توقيع الكوميتات على GitHub باستخدام GPG للحصول على شارة التحقق Verified

إذا كنت تريد أن تظهر كوميتاتك على GitHub بشارة Verified الخضراء، عليك توقيع الكوميتات باستخدام مفتاح GPG. في هذا الدليل، سنتعرف على كيفية إنشاء مفتاح GPG، إضافته إلى GitHub، وتكوين Git لتوقيع الكوميتات تلقائيًا.


الخطوة 1: إنشاء مفتاح GPG

افتح الطرفية (Terminal) واكتب الأمر التالي:

gpg --full-generate-key
  • اختر نوع المفتاح الافتراضي (RSA and RSA).
  • استخدم حجم 4096 بت لتشفير قوي.
  • اختر عدم انتهاء صلاحية المفتاح أو حدد تاريخ انتهاء.
  • أدخل اسمك والبريد الإلكتروني المرتبط بحساب GitHub الخاص بك.
  • يمكنك تعيين عبارة مرور (Passphrase) لحماية المفتاح (اختياري لكن يُنصح به).

الخطوة 2: معرفة معرف مفتاح GPG الخاص بك

بعد إنشاء المفتاح، اعرض المفاتيح السرية مع معرفاتها عن طريق الأمر:

gpg --list-secret-keys --keyid-format LONG

ستظهر لك نتيجة مشابهة لهذا:

/home/user/.gnupg/secring.gpg
------------------------------
sec   rsa4096/53342B0F19EC835B 2025-05-20 [SC]
      1234ABCD5678EF90ABCDEF1234567890ABCDEF12
uid           [ultimate] Your Name <[email protected]>

انسخ معرف المفتاح الطويل بعد الشرطة المائلة /. في هذا المثال هو:

53342B0F19EC835B

الخطوة 3: تصدير مفتاح GPG العام

بعد ذلك، صدّر مفتاحك العام بصيغة ASCII لإضافته إلى GitHub:

gpg --armor --export 53342B0F19EC835B

سيظهر لك نص يبدأ بـ:

-----BEGIN PGP PUBLIC KEY BLOCK-----
...
-----END PGP PUBLIC KEY BLOCK-----

انسخ النص بالكامل.


الخطوة 4: إضافة مفتاح GPG إلى GitHub

  1. افتح [إعدادات GitHub → SSH and GPG keys](https://github.com/settings/keys).
  2. اضغط على New GPG key.
  3. ألصق مفتاحك العام في المربع المخصص.
  4. اضغط Add GPG key للحفظ.

الخطوة 5: تكوين Git لاستخدام مفتاح GPG

أخبر Git باستخدام مفتاح GPG الخاص بك لتوقيع الكوميتات عبر الأمر:

git config --global user.signingkey 53342B0F19EC835B

وقم بتفعيل توقيع الكوميتات تلقائيًا:

git config --global commit.gpgsign true

الخطوة 6: إنشاء كوميتات موقعة

الآن، عندما تنشئ كوميت، سيقوم Git بتوقيعه تلقائيًا:

git commit -m "رسالة الكوميت الخاصة بك"

أو يمكنك توقيع كوميت محدد يدويًا:

git commit -S -m "رسالة الكوميت الخاصة بك"

الخطوة 7: الدفع والتحقق

ادفع الكوميتات إلى GitHub:

git push

افتح الكوميت على GitHub، سترى بجانب رسالة الكوميت شارة Verified الخضراء!


الخلاصة

بإنشاء مفتاح GPG، وإضافته إلى GitHub، وتكوين Git لتوقيع الكوميتات، تثبت أن الكوميتات صادرة منك بالفعل. هذا يزيد من أمان وثقة مشروعك.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment