Git Screening Crash Course

Built for fast preparation: commands, concepts, practice, and a final quiz.

1. Git Basics

What Git is

Git is a version control system. It records changes to files, lets you return to older versions, and makes teamwork easier.

Three areas to remember

AreaMeaning
Working directoryThe files you are currently editing.
Staging areaThe changes selected for the next commit.
RepositoryThe saved commit history.
Core flow:
edit files → git add → git commit

2. Start a Repository

Create a new repository

mkdir practice-project
cd practice-project
git init

git init creates a hidden .git directory that stores the project history.

Check the repository

git status

This is one of the most important commands. Use it whenever you are unsure what Git sees.

Configure your identity

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

3. Add and Commit

git add filename.txt
git add .
git commit -m "Add initial project files"

git add . stages all current changes in the folder. A commit is a saved snapshot.

Common mistake: git add does not permanently save the change. The change is saved to history only after git commit.

View history

git log
git log --oneline

4. Branches and Merging

git branch
git switch -c feature-login
git switch main
git merge feature-login

A branch is an independent line of development. You normally create a branch, make commits, switch back to main, then merge it.

Older command you may see

git checkout -b feature-login

This also creates and switches to a new branch.

Merge conflict basics

A conflict happens when Git cannot automatically combine competing edits. Open the conflicted file, choose the correct content, remove the conflict markers, then run:

git add conflicted-file.txt
git commit

5. Remote Repositories

git clone https://example.com/repository.git
git remote -v
git pull
git push

First push from a new local repository

git remote add origin https://example.com/repository.git
git branch -M main
git push -u origin main
Remember: git fetch downloads remote information. git pull downloads and integrates it into your current branch.

6. Undoing Changes

Discard an unstaged file change

git restore filename.txt

Unstage a file but keep the edit

git restore --staged filename.txt

Reverse a committed change safely

git revert COMMIT_ID

git revert creates a new commit that reverses an earlier one. It is safer for shared branches than rewriting history.

Be careful with: git reset --hard. It can permanently discard local work.

7. Practical Screening Scenarios

Scenario 1: Save a new file

git status
git add report.txt
git commit -m "Add report"

Scenario 2: Work on a feature without changing main

git switch -c feature-dashboard
# edit files
git add .
git commit -m "Build dashboard"
git switch main
git merge feature-dashboard

Scenario 3: Update before pushing

git pull
git push

Scenario 4: You staged the wrong file

git restore --staged wrong-file.txt

8. Command Checklist

9. Final Quiz

1. Which command shows changed, staged, and untracked files?

2. Which command stages all changes?

3. Which command creates and switches to a branch?

4. Which command unstages a file while keeping the edit?

5. Which command downloads and integrates remote changes?