Sure!
Here's a detailed explanation of each command listed under Common
Follow-up Commands in git, with clear examples and use cases:
1. Stage a File
Command:
git add <filename>
What it does:
Moves changes from the working directory to the staging area (index), preparing them
to be committed.
Example:
git add [Link]
This tells Git:
"I’m ready to include [Link] in the next commit."
You can also stage all files with:
git add .
2. Unstage a File
Command:
git reset HEAD <filename>
What it does:
Removes a file from the staging area, but keeps the changes in your working directory.
Example:
git reset HEAD [Link]
This tells Git:
"I changed [Link], but I don’t want to commit it yet."
It doesn’t undo your file changes; it just removes it from being committed.
3. Commit Staged Changes
Command:
git commit -m "Your message"
What it does:
Creates a new commit using the files in the staging area and attaches a message
describing what you did.
Example:
git commit -m "Added login page and fixed validation bug"
The commit is saved in your local repository.
4. See Full Diff (Unstaged Changes)
Command:
git diff
What it does:
Shows the exact line-by-line changes in files that you’ve modified but haven’t staged
yet.
Example:
If you edited [Link] but haven’t added it with git add, git diff shows what lines were
added/removed.
5. See Staged Diff (Ready to Commit)
Command:
git diff --cached
What it does:
Shows the differences between the staging area and the last commit.
Example:
If you already ran git add [Link], then:
git diff --cached
will show what’s about to be committed.
Summary Table:
Action Command What It Does
Stage a file git add [Link] Prepares the file for commit
Unstage a file git reset HEAD [Link] Removes the file from staging
git commit -m
Commit changes Saves staged changes to Git
"message"
See unstaged Shows what you changed but haven't
git diff
changes added
See staged changes git diff --cached Shows what will be committed
How to Use git status in Git
The git status command is very simple to use — it doesn't need any arguments!
Basic Usage
git status
Run this command inside a Git repository folder (your project directory).
Step-by-Step Example
1. Create or go to a Git project:
cd my-project/
2. Check the status:
git status
Output:
On branch master
nothing to commit, working tree clean
Example With Changes
1. Modify or add a file:
echo "Hello" >> [Link]
2. Run git status again:
git status
Output:
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
modified: [Link]
What To Do Next?
Goal Command
Stage the file git add [Link]
Check status again git status
Commit the changes git commit -m "Updated [Link]"
Push to GitHub git push origin master
Summary:
• Just type git status and press Enter
• It tells you:
o Current branch
o Which files are staged
o Which files are not staged
o Which files are untracked
git clone – What It Does & How to Use It
The git clone command is used to create a copy of a remote Git repository on your
local machine. It downloads all files, branches, and the full version history.
Basic Syntax
git clone <repository-url>
Example
git clone [Link]
This will:
• Create a new folder called MyGitRepo
• Download all files from the main or master branch
• Include the entire commit history
• Set up origin as the default remote (to fetch or push later)
Result:
MyGitRepo/
├── [Link]
├── [Link]
├── .git/ ← hidden folder with all version control info
You Can Also:
Goal Command
Clone into a custom folder name git clone <repo-url> my-folder
Use SSH instead of HTTPS git clone git@[Link]:username/[Link]
Behind the Scenes
git clone =
git init + git remote add + git fetch + git checkout
HTTPS vs SSH URLs
Type URL Format Notes
Easier, but asks for credentials unless token
HTTPS [Link]
saved
Requires SSH key setup but avoids repeated
SSH git@[Link]:user/[Link]
login
What does git rm do?
The git rm command removes files from your Git repository. It:
• Deletes the file from your working directory (your local folder)
• Stages the removal so that when you commit, Git records the file deletion
Usage:
git rm <filename>
What happens when you run git rm filename?
• The file filename is deleted from your local disk
• The file removal is staged (ready to be committed)
• After committing, the file will be removed from the repository history from that
point onward
Example:
git rm [Link]
git commit -m "Remove [Link]"
This deletes [Link] from your folder and records that deletion in Git history.
Important:
• If you want to remove a file from Git but keep it locally (don’t delete it from your
disk), use:
git rm --cached <filename>
This removes the file from tracking but leaves it in your folder.