Git Fundamentals
- 93Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is a version control system, and what does it record?
93 questions
- 1
What is a version control system, and what does it record?
Model answer
A version control system records changes to code over time in a repository, allowing the project’s history to be inspected.
Explanation
The history can show what changed, who changed it, and when and why the change was made.
- 2
How can version control help when a change causes a problem?
Model answer
It lets you restore the project to an earlier state.
Explanation
Saved project history provides earlier versions to return to if something goes wrong.
- 3
Why is storing full copies of a project in separate folders an inadequate substitute for version control?
Model answer
It is slow and does not scale well, especially when multiple people need to work on the same project.
Explanation
Without version control, people may have to exchange entire copies and manually merge their changes.
- 4
How do centralized and distributed version control systems differ in where project history is kept?
Model answer
In a centralized system, team members connect to a central server; in a distributed system, each member has a copy of the project and its history.
Explanation
A local copy of the history is a key feature of distributed version control.
- 5
What is the single point of failure in a centralized version control system, and what happens if it fails?
Model answer
The central server is the single point of failure; if it goes offline, collaboration and saving project snapshots may have to wait.
Explanation
The team depends on that server to obtain the latest code and share changes.
- 6
What can team members do with a distributed version control system when the central server is offline?
Model answer
They can save snapshots locally and synchronize work directly with one another.
Explanation
Each team member has a local copy of the project and its history.
- 7
Name two centralized and two distributed version control systems mentioned in the material.
Model answer
Subversion and Microsoft Team Foundation Server are centralized; Git and Mercurial are distributed.
Explanation
These examples illustrate the two version-control architectures.
- 8
What characteristics are given as reasons for Git’s popularity?
Model answer
Git is free, open source, fast, and scalable.
Explanation
The material identifies these qualities as reasons Git is widely used.
- 9
Why are branching and merging notable advantages of Git over systems such as Subversion or TFS?
Model answer
Branching and merging are very fast in Git, while they can be slow and painful in those other systems.
Explanation
Fast branching and merging support working on multiple lines of work and combining them.
- 10
Why is Git a useful skill for someone seeking a software development job?
Model answer
Git is widely used in software projects and commonly appears as a requirement in software developer job descriptions.
Explanation
Knowing Git helps developers track project history and collaborate effectively.
- 11
What are three ways to use Git, and what kinds of Git features do code editors typically provide?
Model answer
Git can be used through the command line, editor or IDE integrations, and dedicated graphical interfaces; editors commonly provide basic Git features.
Explanation
The material gives VS Code’s Source Control panel as an example of editor integration.
- 12
Why might a Git user still need the command line even if they prefer a graphical interface?
Model answer
GUI tools may not support every command, and some situations require using a command line, such as working remotely without permission to install a GUI.
Explanation
Knowing the command line avoids being blocked when a graphical tool is unavailable or limited.
- 13
Why can the command line be useful when working on a remote server?
Model answer
A GUI tool may be unavailable or impossible to install, while the command line is generally available.
Explanation
Remote access and installation restrictions can make command-line Git necessary.
- 14
What is a sensible approach to choosing between Git’s command line and a GUI?
Model answer
Use the tool that best suits the task, and be prepared to use both.
Explanation
A GUI can be suitable for some work, while the command line can be faster or more accessible for other tasks.
- 15
What does the command
git --versiondo, and why might someone run it before starting?Model answer
It displays the installed Git version, helping you check whether Git is installed and which version you have.
Explanation
The material recommends installing a current version if the installed version is outdated.
- 16
What is Git Bash, and why is it recommended for Windows users in the tutorial?
Model answer
Git Bash is a command-line application installed with Git for Windows that emulates a Unix or Linux environment; it makes the commands and interface more similar to those used in the tutorial.
Explanation
It is an alternative to the built-in Windows command prompt for running Git commands.
- 17
How can a user access Git’s full documentation for a command, and how can they request a brief summary?
Model answer
Use
git <command> --helpfor full documentation andgit <command> -hfor a short summary.Explanation
The full help can be viewed in a browser or terminal pager; pressing
qexits the pager. - 18
What configuration levels does Git provide, and what scope does each level affect?
Model answer
System settings apply to all users on the computer, global settings apply to all repositories for the current user, and local settings apply to the current repository.
Explanation
These levels let users set computer-wide, user-wide, or repository-specific preferences.
- 19
Which identity settings should a user configure in Git, and what information do they contain?
Model answer
Configure
user.nameanduser.emailwith the user’s name and email address.Explanation
Git records author information for commits.
- 20
How does
git config --globalspecify the scope of a configuration setting?Model answer
The
--globaloption makes the setting apply to all repositories belonging to the current user.Explanation
The option selects the global configuration level.
- 21
Why are quotation marks used around some Git configuration values but not others?
Model answer
Quotation marks are needed when a value contains spaces; a value without spaces, such as an email address, does not require them.
Explanation
Quotes ensure a multiword value is treated as one value.
- 22
How can a user configure Git to open VS Code as its default editor, and what does the
--waitoption do?Model answer
Set
core.editortocode --wait;--waitmakes the terminal wait until the VS Code window is closed.Explanation
The editor command must be accessible, for example by adding VS Code to the system path.
- 23
What does
git config --global -eallow a user to do?Model answer
It opens the global Git configuration file in the configured default editor so the user can inspect or edit settings.
Explanation
The file contains sections such as
userandcorewith their associated settings. - 24
How do Windows and macOS or Linux differ in their usual end-of-line characters?
Model answer
Windows typically uses carriage return plus line feed, while macOS and Linux use line feed.
Explanation
Different conventions can cause problems when collaborators use different operating systems.
- 25
What does the
core.autocrlfsetting control, and which value is recommended for Windows?Model answer
It controls how Git handles end-of-line conversions; on Windows, the recommended value is
true.Explanation
With this setting, Git removes carriage returns when storing code and adds them when checking code out on Windows.
- 26
Which
core.autocrlfvalue is recommended for macOS or Linux, and how does it handle line endings?Model answer
The recommended value is
input; Git modifies line endings when storing code but does not add carriage returns when checking it out.Explanation
This can remove accidentally added carriage returns from content stored in the repository.
- 27
What is a Git repository, and where does Git keep its repository data inside a project?
Model answer
A repository stores information about project history; Git keeps this data in a hidden
.gitdirectory inside the project directory.Explanation
The
.gitdirectory is created when a repository is initialized. - 28
What does
git initdo?Model answer
It initializes a new, empty Git repository in the current directory.
Explanation
The command creates the hidden
.gitdirectory that Git uses to manage the repository. - 29
Why should a user avoid changing or deleting the
.gitdirectory?Model answer
It contains Git’s repository data; deleting it removes the repository and its project history.
Explanation
Its internal structure is an implementation detail, so ordinary Git users should not need to edit it.
- 30
Why might
lsfail to show the.gitdirectory, and how can it be made visible in a Unix-like terminal?Model answer
The directory is hidden by default;
ls -alists hidden entries as well.Explanation
The
-aoption includes all directory entries in the listing. - 31
What is a Git commit, and what does it represent?
Model answer
A commit is a saved snapshot of the project at a particular point in time.
Explanation
A series of commits records the project’s development history.
- 32
What is the staging area, and how does it fit into the basic Git workflow?
Model answer
The staging area, also called the index, holds the changes proposed for the next commit; users stage changes, review them, and then commit them.
Explanation
It provides an intermediate step between editing files and recording a snapshot.
- 33
Does the staging area automatically become empty after a commit? Explain.
Model answer
No. After a commit, the staging area reflects the snapshot just recorded, so it contains the same project state as the commit.
Explanation
Later changes must be staged to update the proposed snapshot.
- 34
What happens if a file is edited after it has been staged but the edit is not staged again?
Model answer
The staging area retains the earlier staged snapshot, while the working directory contains the newer edit.
Explanation
Running
git addagain stages the updated file content. - 35
How does Git represent a file deletion in the staging area?
Model answer
The deletion must be staged, after which the file is absent from the proposed next snapshot.
Explanation
Adding the changed path stages the deletion even though the file no longer exists in the working directory.
- 36
What information does a Git commit contain, according to the material?
Model answer
A commit has a unique identifier, author and date information, a message, and a complete snapshot of the project at that point.
Explanation
This information makes commits identifiable and useful for understanding project history.
- 37
Does Git store only the differences between commits? Explain how the material describes Git’s snapshots.
Model answer
No. Each commit represents a complete snapshot of the project rather than merely a list of changes.
Explanation
Git can restore an earlier project state from its stored snapshots.
- 38
How can Git store complete snapshots without simply duplicating all file contents each time?
Model answer
Git compresses file contents and avoids storing duplicate content.
Explanation
These techniques make Git’s storage of project history efficient.
- 39
Why are newly created project files not automatically tracked when a repository is initialized?
Model answer
Git does not automatically begin tracking every file; users must add files they want Git to track.
Explanation
Even an existing project with many files requires the user to select files for tracking.
- 40
How can
git addbe used to stage one file, several files, matching files, or an entire directory?Model answer
Specify a filename, list multiple filenames, use a pattern such as
*.txt, or use.to add the current directory recursively.Explanation
The chosen paths determine which changes enter the staging area.
- 41
Why should users be careful when staging an entire directory with
git add .?Model answer
It can stage files that should not be shared, such as large binary files or generated logs.
Explanation
Unwanted files can increase repository size or add irrelevant content.
- 42
What does
git statusshow?Model answer
It reports the state of the working directory and staging area, including untracked, modified, and staged files.
Explanation
It helps users see which changes are ready for a commit and which are not.
- 43
How can a user make a commit with a short message from the command line?
Model answer
Use
git commit -m "message".Explanation
The
-moption supplies the commit message directly in the command. - 44
How can a user write a longer commit message with additional context?
Model answer
Run
git commitwithout a message option so Git opens the configured editor, then write a short summary followed by a blank line and a longer description.Explanation
The longer description can explain relevant context or constraints that a brief summary cannot convey.
- 45
What is the purpose of a commit message?
Model answer
It describes what the snapshot represents so that the project history is useful to the author and teammates.
Explanation
Clear messages make it easier to understand why a project state was recorded.
- 46
What makes a commit too small or too large, and what is a better target?
Model answer
Committing after every trivial edit is too small, while waiting until a large feature or several days of work are complete is too large; commit at meaningful checkpoints.
Explanation
Checkpoints create a useful history and make it easier to recover from mistakes.
- 47
What does it mean for a commit to represent a logically separate change set?
Model answer
It means the commit groups one coherent unit of work, such as a bug fix, without mixing in an unrelated change such as a typo correction.
Explanation
Separate changes should be recorded in separate commits when they serve different purposes.
- 48
Why does staging help keep unrelated changes out of the same commit?
Model answer
It lets users select and review exactly which changes will be included in the next snapshot, and unstage changes that belong elsewhere.
Explanation
The staging area provides control over the contents of a commit.
- 49
What commit-message wording convention does the material describe as common?
Model answer
Many people use the present tense, such as “Fix the bug.”
Explanation
Whatever wording convention a team chooses, its members should use it consistently.
- 50
When can
git commit -a -m "message"be used to skip a separate staging step, and what limitation should users remember?Model answer
It can commit changes to already tracked, modified files without a separate
git add; it does not stage new untracked files.Explanation
The material recommends staging and reviewing changes in most cases rather than routinely bypassing the staging area.
- 51
How can a user remove a file from both the working directory and the staging area in one command?
Model answer
Use
git rm <file>.Explanation
Unlike a regular filesystem removal,
git rmstages the deletion as well as removing the working copy. - 52
What occurs when a file is deleted with a regular filesystem command rather than
git rm?Model answer
The file is removed from the working directory but remains represented in the staging area until the deletion is staged.
Explanation
The user can stage the deletion with
git addor usegit rmto do both steps together. - 53
How does Git treat a manual rename or move before its changes are staged?
Model answer
It sees a deletion of the old path and a new, untracked file at the new path; staging both changes lets Git recognize the rename.
Explanation
A manual rename changes the working directory first, and the corresponding changes must then be staged.
- 54
What does
git mvdo differently from manually moving a file and then staging the changes?Model answer
git mvmoves or renames the file in the working directory and stages the move in one operation.Explanation
It combines the filesystem move with the relevant staging changes.
- 55
Why should a project use a
.gitignorefile?Model answer
It tells Git to ignore specified files or directories that should not be tracked or shared, such as generated logs or compiled binaries.
Explanation
Ignoring these files can prevent unnecessary repository growth and avoid sharing files each developer can generate locally.
- 56
Where should a project’s
.gitignorefile be placed, and what does an entry such aslogs/mean?Model answer
Place
.gitignorein the project root;logs/tells Git to ignore the directory namedlogs.Explanation
The file can contain multiple filenames, directories, and patterns.
- 57
Can adding an already tracked file to
.gitignorestop Git from reporting changes to it?Model answer
No.
.gitignoredoes not stop tracking a file that is already tracked.Explanation
The file must first be removed from the index while being retained in the working directory if it should no longer be tracked.
- 58
How can a user remove a directory from Git’s index without deleting it from the working directory?
Model answer
Use
git rm --cached -r <directory>.Explanation
--cachedremoves the paths from the index, and-rapplies the removal recursively to a directory. - 59
Why might compiled files, such as Java class files, be excluded from a repository?
Model answer
They are generated during compilation and can be recreated, so including them is often unnecessary.
Explanation
Git ignore templates provide patterns for excluding generated files and other common unwanted content.
- 60
What two columns does
git status -suse, and what does each column represent?Model answer
The left column represents the staging area, and the right column represents the working directory.
Explanation
A status code in the right column alone indicates a working-directory change that is not staged.
- 61
In short status output, what do
M,A, and??indicate?Model answer
Mindicates a modified file,Aindicates an added file, and??indicates an untracked file.Explanation
The column containing the code helps show whether a change is staged or only in the working directory.
- 62
Why might short status show changes for the same file in both columns?
Model answer
The staged version and the working-directory version differ because the file was edited again after being staged.
Explanation
Restaging the file updates the index to match its current working-directory content.
- 63
What does
git diffshow when run without arguments?Model answer
It shows unstaged differences between the working directory and the staging area.
Explanation
If there is no output, there are no unstaged differences to show.
- 64
What does
git diff --stagedshow?Model answer
It shows differences between the staging area and the last commit—the changes proposed for the next commit.
Explanation
Reviewing this output helps users inspect staged changes before committing.
- 65
In a Git diff, what do minus and plus signs indicate?
Model answer
Minus signs mark lines removed from the old version, and plus signs mark lines added in the new version.
Explanation
Diff output compares an older copy with a newer copy of a file.
- 66
What is a diff hunk, and why does Git show only a portion of a large file?
Model answer
A hunk is a section of a file’s diff with a header giving context about the changed lines; Git can show only relevant chunks instead of an entire large file.
Explanation
Hunk headers identify the portions and line ranges shown in the comparison.
- 67
What does a diff header showing an old file range of
0,0communicate for a newly added file?Model answer
There were no lines in an old version of that file because it did not exist in the previous snapshot.
Explanation
A new file is compared against the absence of that file in the last commit.
- 68
What roles do
diff.toolanddifftool.<name>.cmdplay when configuring a visual diff tool?Model answer
diff.toolnames the default diff tool, anddifftool.<name>.cmdspecifies the command Git uses to launch it.Explanation
The launch command can include placeholders for the old and new file copies.
- 69
Why might a visual diff tool be helpful, and what does Git use the local and remote placeholders for when launching it?
Model answer
A visual tool can make file comparisons easier to inspect; the local and remote placeholders represent the two versions being compared.
Explanation
For example, the comparison may be between the staged copy and the working-directory copy.
- 70
What should a user review before creating a commit, and why?
Model answer
Review the staged changes to verify that the intended, correct code is going into the commit.
Explanation
Status shows affected files, while diff output reveals the actual lines changed.
- 71
How does
git logpresent a repository’s commits by default?Model answer
It lists commits from newest to oldest, including information such as the identifier, author, date, and message.
Explanation
The output may span multiple pages in a terminal pager.
- 72
What is a Git commit identifier, and what does it look like?
Model answer
It is a unique identifier Git generates for a commit, represented as a 40-character hexadecimal string.
Explanation
It functions as an identifier rather than as a revision number that increases over time.
- 73
What does
git log --onelinedisplay compared with the default log output?Model answer
It displays a compact summary with a shortened commit identifier and the one-line commit message.
Explanation
The shortened identifier is sufficient when it uniquely identifies the commit.
- 74
What does adding
--reverseto a one-line Git log change?Model answer
It reverses the displayed order so the earliest commit appears first and the latest commit last.
Explanation
The ordinary log order is newest to oldest.
- 75
What are
HEADand a branch such asmasterin the history output?Model answer
HEADrefers to the current branch, whilemasteris the name of a branch representing a main line of work.Explanation
Git uses the current branch reference to identify which branch the user is working on.
- 76
How can a user inspect the changes introduced by a particular commit?
Model answer
Use
git showwith that commit’s identifier or a reference to it.Explanation
The output includes commit details and a diff of its changes.
- 77
How can a commit be identified without typing its complete identifier?
Model answer
Use an unambiguous prefix of its identifier.
Explanation
The prefix must be long enough to distinguish it from other commit identifiers.
- 78
How can
HEAD~1be used to refer to a commit?Model answer
HEAD~1refers to the commit one step before the currentHEADcommit.Explanation
The number after the tilde indicates how many commits to go back.
- 79
How can a user display the exact version of one file stored in a commit instead of the commit’s diff?
Model answer
Use
git show <commit>:<path-to-file>.Explanation
The colon and file path select that file’s contents from the specified commit.
- 80
What does
git ls-treelist, and why is a directory described as a tree?Model answer
It lists files and directories stored in a commit; a directory is called a tree because it contains a hierarchy of files and subdirectories.
Explanation
The tree structure represents hierarchical filesystem information.
- 81
How does Git represent files and directories as objects in its database?
Model answer
Files are represented as blobs and directories as trees; commits and tags are also Git objects.
Explanation
Git can display an object’s contents with
git showwhen given its identifier. - 82
Why does Git give objects identifiers based on their content, as described in the material?
Model answer
The identifier is generated from the object’s content, so it identifies that stored object.
Explanation
The material illustrates this with identifiers for files and directories in a commit’s tree.
- 83
How can
git restore --staged <file>be used when a staged change should not be in the next commit?Model answer
It removes that file’s staged changes from the index while leaving the changes in the working directory.
Explanation
The file can then be edited further or staged later as part of a different commit.
- 84
What version does Git use when restoring a file from the staging area by default?
Model answer
It uses the version from the last commit.
Explanation
The last commit is the source environment for restoring a staged file by default.
- 85
What happens when a newly added, uncommitted file is restored with
git restore --staged?Model answer
It is removed from the staging area and becomes an untracked file in the working directory.
Explanation
There is no version of that new file in the last commit to restore into the index.
- 86
How can a user discard unstaged changes to a tracked file?
Model answer
Use
git restore <file>to replace the working-directory version with the staged version.Explanation
This discards local edits that have not been staged.
- 87
Why does
git restore <file>not remove an untracked file?Model answer
Git has not been tracking the file and has no earlier staged or committed version to restore.
Explanation
Untracked files require a different command if they are to be removed.
- 88
What does
git cleando, and why does Git require force for this operation?Model answer
It removes untracked files; force is required because the removed files cannot be recovered through Git if they were not tracked.
Explanation
The force option is commonly supplied as
-fto confirm this destructive action. - 89
What does the
-doption add when used withgit clean -f?Model answer
It allows Git to remove whole untracked directories as well as untracked files.
Explanation
The combined command
git clean -fdremoves untracked files and directories. - 90
How can a deleted tracked file be restored from a commit before the latest commit?
Model answer
Use
git restore --source=HEAD~1 <file>.Explanation
The source option selects the previous commit as the version to restore.
- 91
What is the difference between restoring a deleted file from a previous commit and undoing the commit that deleted it?
Model answer
Restoring the file retrieves an earlier version of that file; undoing or reverting a commit changes the commit history through a separate operation.
Explanation
The material focuses on recovering the file itself rather than undoing the deletion commit.
- 92
When restoring a file, what source does Git use by default if the file is in the working directory versus the staging area?
Model answer
For a working-directory file, Git uses the staging-area version; for a staged file, Git uses the last committed version.
Explanation
The default source is the next environment in the workflow.
- 93
Which type of changes can Git recover using its stored history, and which cannot be recovered through Git?
Model answer
Git can restore versions of tracked files from its stored history, but it cannot recover untracked files removed by cleanup.
Explanation
Only tracked content has versions recorded in Git’s repository data.

Ask anything
We've read this whole study set, so questions about it get the best answers.