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

GitHub Edit Code

Once a repository is cloned, editing its files is just normal local file editing -- Git compares your changes against the last commit, and staging plus committing is how those local edits become part of history before they're ever pushed anywhere.

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

bash
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

bash
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

bash
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

bash
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

bash
git fetch origin
git rebase origin/main

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.