Quick reference for the commands used in these exercises.
Command
Description
git config --global user.name "Name"
Set your name for commits
git config --global user.email "email"
Set your email for commits
git config --global --list
View your Git configuration
Creating & Cloning Repositories
Command
Description
git init
Initialize a new local Git repository
git clone <url>
Clone a remote repository to your machine
Command
Description
git status
Show the state of working directory and staging area
git add <file>
Stage a file for the next commit
git add .
Stage all changed files
git commit -m "message"
Create a commit with a message
git diff
Show unstaged changes
git diff --staged
Show staged changes (what will be committed)
Command
Description
git log
Show commit history
git log --oneline
Show compact commit history
git log --oneline --graph
Show history with branch graph
git show
Show the most recent commit's details
Command
Description
git branch
List local branches
git branch <name>
Create a new branch
git checkout <branch>
Switch to a branch
git checkout -b <name>
Create and switch to a new branch
git switch -c <name>
Create and switch to a new branch (newer syntax)
git branch -d <name>
Delete a merged branch
git branch -D <name>
Force-delete a branch
Command
Description
git remote -v
Show remote URLs
git push
Push commits to the remote
git push -u origin <branch>
Push a new branch and set upstream tracking
git pull
Fetch and merge changes from the remote
git fetch
Download remote changes without merging
Command
Description
git restore <file>
Discard unstaged changes to a file
git restore --staged <file>
Unstage a file (keep changes in working directory)
git commit --amend
Modify the most recent commit
When Git can't automatically merge, it marks conflicts in the file:
<<<<<<< HEAD
your changes
=======
their changes
>>>>>>> branch-name
To resolve:
Edit the file — keep what you want, remove the markers
git add <file> — mark as resolved
git commit — complete the merge
Concept
Description
Repository
A project containing files and their Git history
Remote
A version of your repo hosted elsewhere (e.g., GitHub)
Origin
The default name for the remote you cloned from
Fork
Your personal copy of someone else's repository
Pull Request (PR)
A proposal to merge changes from one branch to another
Merge
Combining changes from one branch into another
Clone
Downloading a complete copy of a remote repository
Push
Uploading local commits to a remote repository
Pull
Downloading and merging remote changes locally