← Back to Git Course | Chapter 4: Remote Repositories | Lesson 2 of 11

GitHub Edit Code

एक repository clone होने के बाद, इसकी files edit करना बस normal local file editing है -- Git आपके changes को last commit के against compare करता है, और staging plus committing वह तरीका है जिससे वे local edits कहीं भी push होने से पहले history का हिस्सा बनते हैं।
Syntax
bash
git diff
git diff --staged
git add file_name
git commit -m "message"

Clone करने के बाद Local Working Directory

एक repository clone करना इसकी पूरी history download करता है और हर tracked file की एक working copy को एक local folder में checkout करता है, इसलिए clone करने के तुरंत बाद, working directory, staging area, और remote सब exactly same content रखते हैं।

उदाहरण: The Local Working Directory After Cloning

bash
git clone https://github.com/user/repo.git
git status

Cloned Files में Changes करना

किसी भी text editor या IDE का इस्तेमाल एक cloned file का content बदलने के लिए किया जा सकता है, क्योंकि Git सिर्फ इसकी परवाह करता है कि disk पर क्या है -- किसी tracked file का content last commit से अलग होते ही, Git इसे working directory में modified mark कर देता है।

उदाहरण: Making Changes to Cloned Files

bash
echo "Updated content" >> README.md

git diff से क्या बदला Check करना

git diff current working directory content को last commit के against compare करता है और exact lines print करता है जो add या remove हुईं, जो इसे stage करना है या नहीं decide करने से पहले एक edit review करने का सबसे तेज़ तरीका है।

उदाहरण: Checking What Changed with git diff

bash
git diff

Local Edits Stage और Commit करना

Local edits सिर्फ repository की history का हिस्सा तभी बनते हैं जब उन्हें git add से stage किया जाए और git commit से record किया जाए -- उस point तक, changes सिर्फ working directory में exist करते हैं और अगर folder delete हो जाए तो खो जाएँगे।

उदाहरण: Staging and Committing Local Edits

bash
git add README.md
git commit -m "Update README"

Push करने से पहले Local Edits को Sync में रखना

Local commits push करने से पहले, git fetch (या git pull) चलाना check करता है कि क्या इस बीच remote आगे बढ़ा है, और local काम को latest remote history पर rebase या merge करना एक rejected push से बचाता है और shared history को follow करना आसान रखता है।

उदाहरण: Keeping Local Edits in Sync Before Pushing

bash
git fetch origin
git rebase origin/main
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. files edit करना और GitHub से change देखने की उम्मीद करना, जबकि आपको पहले commit और push करना ज़रूरी है।
  2. git add के बाद git diff चलाना और कुछ न देखना, क्योंकि staged changes को git diff --staged चाहिए।
  3. गलत clone में, या गलत folder में एक file edit करना, और git status में change न देखना।

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.