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.
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.
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
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.
- Go to GitHub Settings → SSH and GPG keys.
- Click New GPG key.
- Paste the copied public key into the text box.
- Click Add GPG key to save.
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
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"
Push your commits to GitHub:
git push
Check your commit on GitHub — it should show a green Verified badge next to your commit message!
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.
كيفية توقيع الكوميتات على GitHub باستخدام GPG للحصول على شارة التحقق Verified
إذا كنت تريد أن تظهر كوميتاتك على GitHub بشارة Verified الخضراء، عليك توقيع الكوميتات باستخدام مفتاح GPG. في هذا الدليل، سنتعرف على كيفية إنشاء مفتاح GPG، إضافته إلى GitHub، وتكوين Git لتوقيع الكوميتات تلقائيًا.
الخطوة 1: إنشاء مفتاح GPG
افتح الطرفية (Terminal) واكتب الأمر التالي:
RSA and RSA
).الخطوة 2: معرفة معرف مفتاح GPG الخاص بك
بعد إنشاء المفتاح، اعرض المفاتيح السرية مع معرفاتها عن طريق الأمر:
ستظهر لك نتيجة مشابهة لهذا:
انسخ معرف المفتاح الطويل بعد الشرطة المائلة
/
. في هذا المثال هو:الخطوة 3: تصدير مفتاح GPG العام
بعد ذلك، صدّر مفتاحك العام بصيغة ASCII لإضافته إلى GitHub:
سيظهر لك نص يبدأ بـ:
انسخ النص بالكامل.
الخطوة 4: إضافة مفتاح GPG إلى GitHub
الخطوة 5: تكوين Git لاستخدام مفتاح GPG
أخبر Git باستخدام مفتاح GPG الخاص بك لتوقيع الكوميتات عبر الأمر:
وقم بتفعيل توقيع الكوميتات تلقائيًا:
git config --global commit.gpgsign true
الخطوة 6: إنشاء كوميتات موقعة
الآن، عندما تنشئ كوميت، سيقوم Git بتوقيعه تلقائيًا:
git commit -m "رسالة الكوميت الخاصة بك"
أو يمكنك توقيع كوميت محدد يدويًا:
git commit -S -m "رسالة الكوميت الخاصة بك"
الخطوة 7: الدفع والتحقق
ادفع الكوميتات إلى GitHub:
افتح الكوميت على GitHub، سترى بجانب رسالة الكوميت شارة Verified الخضراء!
الخلاصة
بإنشاء مفتاح GPG، وإضافته إلى GitHub، وتكوين Git لتوقيع الكوميتات، تثبت أن الكوميتات صادرة منك بالفعل. هذا يزيد من أمان وثقة مشروعك.