GitHub Edit Code
In this page:
The Local Working Directory After Cloning
Cloning a repository downloads its full history and checks out a working copy of every tracked file into a local folder, so immediately after cloning, the working directory, staging area, and remote all contain exactly the same content.
Example: The Local Working Directory After Cloning
git clone https://github.com/user/repo.git
git status
Making Changes to Cloned Files
Any text editor or IDE can be used to change a cloned file's content, since Git only cares about what's on disk -- as soon as a tracked file's content differs from the last commit, Git marks it as modified in the working directory.
Example: Making Changes to Cloned Files
echo "Updated content" >> README.md
Checking What Changed with git diff
git diff compares the current working directory content against the last commit and prints the exact lines that were added or removed, which is the fastest way to review an edit before deciding whether to stage it.
Example: Checking What Changed with git diff
git diff
Staging and Committing Local Edits
Local edits only become part of the repository's history once they're staged with git add and recorded with git commit -- until that point, changes exist only in the working directory and would be lost if the folder were deleted.
Example: Staging and Committing Local Edits
git add README.md
git commit -m "Update README"
Keeping Local Edits in Sync Before Pushing
Before pushing local commits, running git fetch (or git pull) checks whether the remote has moved ahead in the meantime, and rebasing or merging local work onto the latest remote history avoids a rejected push and keeps the shared history easy to follow.
Example: Keeping Local Edits in Sync Before Pushing
git fetch origin
git rebase origin/main
Chapter Quiz — Complete all 11 topics to unlock
0/11 topics done
Complete these topics first: