Git Signing Commits और Tags
In this page:
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
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
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
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
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
gpg --armor --export ABCD1234
# paste into GitHub Settings > SSH and GPG keys
- बिना काम करने वाली GPG key के
commit.gpgsignenable करना, ताकि हर commit एक signing error के साथ fail हो। - एक ऐसी
user.signingkeyइस्तेमाल करना जो आपकी commits के email से match नहीं करती, ताकि platform commit को unverified दिखाए। -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: