0% found this document useful (0 votes)
17 views7 pages

Git Notes

Uploaded by

Sushmitha R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views7 pages

Git Notes

Uploaded by

Sushmitha R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

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 hello.txt

This tells Git:

"I’m ready to include hello.txt 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 hello.txt

This tells Git:

"I changed hello.txt, 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 hello.txt 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 hello.txt, then:

git diff --cached

will show what’s about to be committed.


Summary Table:

Action Command What It Does

Stage a file git add file.txt Prepares the file for commit

Unstage a file git reset HEAD file.txt 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" >> file1.txt

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: file1.txt

What To Do Next?

Goal Command

Stage the file git add file1.txt

Check status again git status

Commit the changes git commit -m "Updated file1.txt"

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 https://github.com/rak109/MyGitRepo.git

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/

├── index.html

├── style.css

├── .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 [email protected]:username/repo.git

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 https://github.com/user/repo.git
saved

Requires SSH key setup but avoids repeated


SSH [email protected]:user/repo.git
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 oldfile.txt

git commit -m "Remove oldfile.txt"

This deletes oldfile.txt 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.

You might also like