Back to courses
Technology beginner

Git and Version Control

Duration0 hours
Modules7
Get started — free →

Course outline

Module 1 Module 1: Introduction to Version Control

Introduction to Version Control

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. What is the primary purpose of a version control system?
  • A. To compile source code into executable programs
  • B. To track changes to files over time and allow you to recover earlier versions
  • C. To automatically deploy applications to production servers
  • D. To encrypt files so only authorized users can read them
Q2. Which of the following best describes a 'commit' in Git?
  • A. A copy of the entire remote repository stored on your computer
  • B. A snapshot of the staged changes saved to the repository history with a message
  • C. A request to merge one branch into another
  • D. A command that permanently deletes files from the working directory
Q3. What is the difference between a centralized and a distributed version control system?
  • A. Centralized systems do not track history, while distributed systems do
  • B. In a distributed system, every developer has a full copy of the repository history, while a centralized system relies on a single central server
  • C. Centralized systems only work with text files, while distributed systems work with binary files
  • D. Distributed systems require an internet connection for every commit, while centralized systems do not
Q4. What does the 'git status' command show?
  • A. The full commit history of the project
  • B. The network speed between you and the remote server
  • C. The current state of the working directory and staging area, including modified and untracked files
  • D. The size of the repository on disk
Q5. Why is it useful to write clear, descriptive commit messages?
  • A. Git cannot function without a commit message
  • B. They make the project history understandable to others and to your future self when tracking down changes
  • C. They automatically generate documentation for the code
  • D. They reduce the file size of the repository
Module 2 Module 2: Setting Up Git and Your First Repository

Setting Up Git and Your First Repository

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. Which command is used to create a new, empty Git repository in the current directory?
  • A. git start
  • B. git init ✓
  • C. git create
  • D. git new repo

Why: The command 'git init' initializes a new Git repository by creating a hidden .git directory in the current folder, which stores all version control metadata.

Q2. Which command sets your name globally so that it is attached to every commit you make on this machine?
  • A. git config --global user.name "Your Name" ✓
  • B. git set name "Your Name"
  • C. git user --name "Your Name"
  • D. git identity add "Your Name"

Why: The 'git config --global user.name' command stores your name in your global Git configuration file, so Git uses it as the author name for all commits in all repositories on that machine.

Q3. What is the purpose of the .gitignore file?
  • A. To store the full commit history of the project
  • B. To list files and patterns that Git should not track ✓
  • C. To define which branch is the default branch
  • D. To store your remote repository credentials

Why: .gitignore is a plain text file where you list files or patterns, such as build outputs, log files, or secret keys, that Git should ignore and not add to version control.

Q4. Which command shows the current state of your working directory and staging area, including untracked and modified files?
  • A. git log
  • B. git status ✓
  • C. git show
  • D. git diff --cached

Why: 'git status' lists which files are modified, staged for commit, or untracked, giving you a snapshot of the current state of your repository.

Q5. Which sequence correctly takes a new file from untracked to committed in a repository?
  • A. git commit, then git add, then git push
  • B. git add, then git commit ✓
  • C. git push, then git add, then git commit
  • D. git commit, then git init, then git add

Why: You first stage a file with 'git add' to prepare it for the next snapshot, then run 'git commit' to permanently record the staged changes in the repository history.

Module 3 Module 3: Tracking Changes: Staging and Committing

Tracking Changes: Staging and Committing

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. What command moves changes from your working directory into the staging area in Git?
  • A. git commit
  • B. git add ✓
  • C. git push
  • D. git stash

Why: git add stages changes, moving them from the working directory into the staging area (index) so they will be included in the next commit. git commit records staged changes, git push uploads commits to a remote, and git stash temporarily shelves changes.

Q2. Which command shows the current status of files in your working directory and staging area?
  • A. git log
  • B. git diff
  • C. git status ✓
  • D. git show

Why: git status lists which files are modified, staged, or untracked. git log shows commit history, git diff shows line-level differences, and git show displays details about a specific commit or object.

Q3. What is the purpose of a commit message?
  • A. It determines which files are tracked by Git
  • B. It describes the changes in the commit so others understand the purpose of the change ✓
  • C. It encrypts the committed content
  • D. It automatically merges branches

Why: A commit message documents what changed and why, helping collaborators and your future self understand the project history. It does not control tracking, encryption, or merging.

Q4. Which command both stages all modified tracked files and creates a commit in one step?
  • A. git commit -a -m "message" ✓
  • B. git add -all commit
  • C. git stage --commit
  • D. git save -m "message"

Why: The -a flag on git commit automatically stages changes to already-tracked files before committing. Note it does not include brand-new untracked files. The other options are not valid Git syntax.

Q5. If you accidentally staged a file with git add and want to unstage it without losing your changes, which command should you use?
  • A. git rm --cached filename
  • B. git reset HEAD filename ✓
  • C. git checkout -- filename
  • D. git delete filename

Why: git reset HEAD filename removes the file from the staging area while keeping your modifications in the working directory. git checkout -- filename would discard your changes, and git delete is not a Git command.

Module 4 Module 4: Branching and Merging

Branching and Merging

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. What command creates a new branch named 'feature-login' and switches to it immediately?
  • A. git branch feature-login
  • B. git checkout -b feature-login ✓
  • C. git new feature-login
  • D. git switch feature-login --create-only

Why: 'git checkout -b feature-login' creates the branch and switches to it in one step. 'git branch feature-login' creates the branch but does not switch to it.

Q2. Which command lists all local branches in a repository?
  • A. git branch ✓
  • B. git show-branches
  • C. git list branches
  • D. git log --branches

Why: Running 'git branch' with no arguments lists all local branches and marks the current branch with an asterisk. The other options are not valid Git commands for this purpose.

Q3. What happens to the commits on a branch when you run 'git merge' from another branch into it?
  • A. The commits are deleted from the source branch
  • B. The commits from the source branch are combined into the current branch ✓
  • C. The current branch is renamed to the source branch
  • D. Nothing changes until you run git push

Why: Merging integrates the changes from the specified branch into the current branch. The source branch itself is left intact unless you delete it manually.

Q4. What is a merge conflict in Git?
  • A. A failure caused by a corrupted repository
  • B. A situation where Git cannot automatically reconcile differing changes to the same lines of a file ✓
  • C. A warning that a branch has no commits
  • D. An error when pushing to a remote repository

Why: A merge conflict occurs when two branches modify the same part of a file differently, so Git cannot decide which change to keep and asks the developer to resolve it manually.

Q5. Which command safely deletes a local branch named 'old-feature' only if it has already been merged?
  • A. git branch -D old-feature
  • B. git remove branch old-feature
  • C. git branch -d old-feature ✓
  • D. git delete old-feature

Why: 'git branch -d' deletes the branch only if its changes are already merged into the current or upstream branch, preventing accidental loss of work. The uppercase -D flag forces deletion regardless of merge status.

Module 5 Module 5: Working with Remote Repositories

Working with Remote Repositories

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. Which command is used to download the contents of a remote repository to your local machine for the first time?
  • A. git pull
  • B. git clone ✓
  • C. git fetch
  • D. git push

Why: git clone creates a full local copy of a remote repository, including its history and branches, and sets up the remote connection automatically. git pull and git fetch require an existing local repository, and git push uploads changes rather than downloading them.

Q2. What is the default name Git gives to the remote repository you cloned from?
  • A. main
  • B. origin ✓
  • C. upstream
  • D. master

Why: When you clone a repository, Git automatically names the source remote 'origin'. This name is a convention, not a requirement, and you can view it with git remote -v.

Q3. Which command uploads your local commits to a remote repository?
  • A. git fetch origin
  • B. git merge origin
  • C. git push origin main ✓
  • D. git clone origin

Why: git push sends your local commits on the specified branch to the remote repository. git fetch and git merge do not upload anything, and git clone is used only to create a new local copy of a repository.

Q4. What is the difference between git fetch and git pull?
  • A. git fetch downloads remote changes without merging them into your current branch, while git pull downloads and merges them. ✓
  • B. git fetch uploads changes, while git pull downloads changes.
  • C. git fetch deletes local branches, while git pull creates them.
  • D. There is no difference; they are aliases for the same command.

Why: git fetch updates your remote-tracking branches without changing your working files, letting you review changes first. git pull is effectively git fetch followed by git merge (or rebase), so it integrates the changes immediately.

Q5. Which command displays the URLs of the remote repositories linked to your local repository?
  • A. git status
  • B. git log
  • C. git remote -v ✓
  • D. git branch -a

Why: git remote -v lists each remote's name along with its fetch and push URLs. git status shows working tree changes, git log shows commit history, and git branch lists branches, not remote URLs.

Module 6 Module 6: Collaborating with Pull Requests

Collaborating with Pull Requests

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. What is the main purpose of a pull request in a Git-based workflow?
  • A. To delete a branch from the remote repository
  • B. To propose changes from one branch and request that they be reviewed and merged into another branch ✓
  • C. To download the latest changes from a remote repository to your local machine
  • D. To create a new local branch from the main branch

Why: A pull request is a way to propose changes made on a branch and ask collaborators to review them before merging into a target branch such as main. Downloading changes is done with fetch or pull, and creating branches is done with git branch or git checkout -b.

Q2. Which command pushes a local feature branch to a remote repository so you can open a pull request from it?
  • A. git fetch origin feature-login
  • B. git push origin feature-login ✓
  • C. git merge feature-login
  • D. git clone feature-login

Why: git push origin feature-login uploads your local feature-login branch to the remote named origin, making it available so a pull request can be opened from it. Fetch downloads changes, merge combines branches locally, and clone copies an entire repository.

Q3. During a code review on a pull request, what is a common way for a reviewer to request changes from the author?
  • A. Deleting the pull request and opening a new one
  • B. Leaving review comments and requesting changes on specific lines of code ✓
  • C. Forcing a merge into the main branch
  • D. Renaming the author's branch

Why: Platforms like GitHub and GitLab let reviewers attach comments to specific lines and submit a review marked as requesting changes. This keeps feedback organized and tied to the relevant code, rather than requiring a new pull request or bypassing review.

Q4. Why do teams often require a pull request to be approved before it can be merged?
  • A. Git does not allow merging without approval
  • B. It helps catch bugs, share knowledge, and maintain code quality through peer review ✓
  • C. It automatically deletes the old branch
  • D. It reduces the size of the repository's history

Why: Requiring approval introduces peer review, which helps find bugs, spreads understanding of the codebase across the team, and enforces quality standards. Git itself does not require approval; this is a workflow or platform policy chosen by the team.

Q5. After a pull request is merged, what is a typical follow-up step for a feature branch?
  • A. Force-push it to the main branch
  • B. Delete the feature branch, since its work now lives in the target branch ✓
  • C. Rebase the main branch onto it
  • D. Convert it into a tag

Why: Once the changes are merged, the feature branch is no longer needed, so deleting it keeps the repository tidy. The work is preserved in the target branch's history, so nothing is lost by removing the branch.

Module 7 Module 7: Resolving Conflicts and Undoing Mistakes

Resolving Conflicts and Undoing Mistakes

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. Which Git command shows the commit history of the current branch, useful for finding a commit to undo?
  • A. git status
  • B. git log ✓
  • C. git diff
  • D. git branch

Why: git log lists the commit history, including commit hashes, authors, dates, and messages. You need those hashes to reference a specific commit when undoing changes. git status shows the working tree state, git diff shows line-level changes, and git branch lists branches.

Q2. You made a commit with a typo in the message and it is your most recent commit, not yet pushed. Which command lets you fix the message?
  • A. git revert HEAD
  • B. git commit --amend ✓
  • C. git reset --hard HEAD~1
  • D. git checkout --message

Why: git commit --amend replaces the most recent commit with a new one, letting you edit its message or add staged changes. git revert creates a new commit that undoes changes, which is unnecessary for a typo. git reset --hard would delete the commit and its changes, and git checkout has no --message option.

Q3. During a merge, Git reports a conflict in a file. What do the markers <<<<<<<, =======, and >>>>>>> indicate?
  • A. Lines that were deleted in the commit
  • B. The boundaries of conflicting sections from each branch that you must resolve manually ✓
  • C. Comments automatically added by Git
  • D. Lines that have been staged for commit

Why: Git inserts these markers to show the conflicting versions: content from your current branch appears between <<<<<<< and =======, and content from the incoming branch appears between ======= and >>>>>>>. You edit the file to keep the correct code, remove the markers, then stage and commit the resolution.

Q4. Which command safely undoes a commit that has already been pushed to a shared branch, without rewriting history?
  • A. git reset --hard
  • B. git commit --amend
  • C. git revert <commit-hash> ✓
  • D. git rebase -i

Why: git revert creates a new commit that reverses the changes of the specified commit. Because it adds history rather than rewriting it, it is safe for shared branches. git reset and git rebase rewrite history, which can cause problems for collaborators, and git commit --amend only applies to the latest local commit.

Q5. You accidentally modified a file and want to discard those unstaged changes, restoring it to the last committed version. Which command does this?
  • A. git restore <file> ✓
  • B. git add <file>
  • C. git merge <file>
  • D. git stash drop

Why: git restore <file> discards working directory changes and restores the file to its last committed state. git add stages changes rather than discarding them, git merge combines branches rather than individual files, and git stash drop deletes a stash entry rather than reverting a file.

Stay in the loop on this course.

We’ll email you when new modules or related material drops. No spam.

Built with Fragment Language. Sovereign architecture — no third-party trackers.
FragRun.mfgAFImemoryFGOwnership: B-Systems.ee