← Back to Git Course | Chapter 8: Best Practices | Lesson 6 of 6

Git Signing Commits और Tags

एक commit sign करना अपने personal wax stamp से एक letter seal करने जैसा है, ताकि दूसरे sure हो सकें कि यह really आपसे आई और बदली नहीं गई।
Syntax
bash
git config --global user.signingkey key_id
git commit -S -m "commit message"
git tag -s tag_name -m "tag message"

Commits क्यों Sign करें

एक GPG-signed commit cryptographically prove करता है कि यह एक specific private key के holder ने authored की, reviewers और CI systems को एक commit की metadata में आसानी से spoofed name/email fields से आगे authorship verify करने का एक तरीका देते हुए -- shared या open-source projects पर supply-chain trust के लिए important।

उदाहरण: Why Sign Commits

bash
git commit -S -m "Signed commit proving authorship"

Sign करने के लिए Git Configure करना

एक बार एक GPG key exist कर ले, Git को बताना ज़रूरी है कि कौन सी key इस्तेमाल करनी है और, optionally, हर commit को automatically sign करने के लिए हर command पर individually -S flag की माँग करने के बजाय।

उदाहरण: Configuring Git to Sign

bash
git config --global user.signingkey ABCD1234
git config --global commit.gpgsign true

एक Commit Sign करना

Signing configured होने पर, एक normal commit workflow unchanged रहता है सिवाय इसके कि Git एक cryptographic signature attach करता है जिसे आप बाद में verify कर सकते हैं -- commit message और diff खुद encrypted नहीं होते, सिर्फ authenticated।

उदाहरण: Signing a Commit

bash
git commit -S -m "Fix login bug"

Tags Sign करना

Release tags regular commits से भी ज़्यादा signing से benefit उठाते हैं, क्योंकि एक tag अक्सर उस exact code को mark करता है जो users को ship होता है -- एक signed tag prove करता है कि release artifact बाद में tampered नहीं हुआ।

उदाहरण: Signing Tags

bash
git tag -s v1.0.0 -m "Signed release"

GitHub Verified Badge

जब एक signed commit की public key आपके GitHub account में upload हो चुकी हो, GitHub अपने web UI में उस commit के बगल में एक green Verified badge दिखाता है -- एक unsigned या गलत तरीके से signed commit कोई badge नहीं दिखाता, या अगर signature match न करे तो एक Unverified warning।

उदाहरण: GitHub Verified Badge

bash
gpg --armor --export ABCD1234
# paste into GitHub Settings > SSH and GPG keys
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. बिना काम करने वाली GPG key के commit.gpgsign enable करना, ताकि हर commit एक signing error के साथ fail हो।
  2. एक ऐसी user.signingkey इस्तेमाल करना जो आपकी commits के email से match नहीं करती, ताकि platform commit को unverified दिखाए।
  3. -S से sign करना लेकिन public key कभी GitHub या GitLab में upload न करना, ताकि signature verified न दिखे।
चैप्टर सारांश
  • Best practices अच्छी habits, commit message quality, और security cover करती हैं।
  • Common mistakes और interview questions आपको typical problems avoid और explain करने में मदद करते हैं।
  • Commits और tags sign करना authorship verify करता है।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.