Git Fundamentals
- 111Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- ←Previous card
- →Next card
What is a version control system?
A system that records changes to code over time in a repository, allowing users to inspect project history and restore earlier states.
Or swipe the card
111 cards
What is a version control system?
A system that records changes to code over time in a repository, allowing users to inspect project history and restore earlier states.
What information can a version control system’s project history reveal?
Who made changes, what they changed, when they made them, and why, as described by the history and commit messages.
How does version control support collaboration compared with manually sharing project copies?
It lets team members track changes and share work without repeatedly sending whole project copies or manually merging them.
What are the two broad categories of version control systems?
Centralized and distributed version control systems.
How does a centralized version control system work?
Team members connect to a central server to obtain the latest code and share their changes.
What is the main risk of centralized version control?
The central server is a single point of failure. If it goes offline, team members cannot collaborate through it or save snapshots there.
How does a distributed version control system differ from a centralized one?
Each team member has a copy of the project and its history, so they can save snapshots locally and may synchronize directly with others if the central server is offline.
Name two centralized and two distributed version control systems.
Subversion and Microsoft Team Foundation Server (TFS) are centralized; Git and Mercurial are distributed.
Why is Git widely used?
It is free, open source, fast, and scalable; operations such as branching and merging are especially fast compared with systems such as Subversion or TFS.
Why is Git an important skill for software developers?
It is used by most software projects and is commonly expected in developer jobs; knowing it helps developers track history and collaborate effectively.
What are common ways to use Git?
Through the command line, Git features built into code editors or IDEs, and dedicated graphical user interface (GUI) tools.
Why learn the Git command line even when using a GUI?
GUIs may not support every command, and a GUI may be unavailable or impossible to install in some environments, such as a remote server.
What is a practical approach to choosing between Git’s command line and GUI tools?
Use the right tool for the task; many developers use both, since some tasks are easier or faster in a GUI and others on the command line.
What is Git Bash, and when is it useful?
A Windows application that provides a command prompt emulating Unix or Linux environments; it is useful for following command-line examples in those environments.
What does
git --versiondo?Displays the installed Git version.
What are the three levels at which Git configuration can be set?
System settings apply to all users on the computer; global settings apply to all repositories for the current user; local settings apply to the current repository.
Which Git configuration level should you use for a preference that applies to all your repositories?
The global level, specified with
git config --global.How do you configure your Git username globally?
Use
git config --global user.name "Your Name". Quotes are needed when the value contains spaces.How do you configure your Git email globally?
Use
git config --global user.email your@email.com. Quotes are unnecessary when the value has no spaces.How do you configure VS Code as Git’s default editor, and what does
--waitdo?Set
core.editortocode --wait;--waitmakes the terminal wait until the VS Code window is closed.How can you edit your global Git configuration in the default editor?
Run
git config --global --edit.Where are Git configuration settings stored, and how are they organized?
In a text file named
.gitconfig; settings are organized into sections such asuserandcore.What line-ending characters are used by Windows versus macOS and Linux?
Windows typically uses carriage return plus line feed (CRLF); macOS and Linux use line feed (LF).
What does Git’s
core.autocrlfsetting control?How Git handles line endings when checking files out of or storing them in the repository.
What
core.autocrlfvalue is recommended for Windows in the material, and what does it do?true: Git removes carriage returns when storing files and adds them when checking files out on Windows.What
core.autocrlfvalue is recommended for macOS or Linux in the material, and what does it do?input: Git removes carriage returns when storing files in the repository but does not modify line endings on checkout.How can you get full documentation for a Git command from the terminal?
Run
git <command> --help, such asgit config --help; press Space to page through andqto quit.How can you get a brief summary of a Git command’s options?
Run
git <command> -h, such asgit config -h.What does
git initdo?Initializes an empty Git repository in the current project directory by creating a
.gitsubdirectory.What is the
.gitdirectory for?It stores Git’s information about the repository and project history.
Why should you avoid manually deleting or changing the
.gitdirectory?It contains the repository’s history and data; removing it causes the project to lose its Git repository and history.
Why might
lsnot show the.gitdirectory, and how can you list it?It is hidden by default. Use
ls -ato show hidden files and directories.What is a Git commit?
A recorded snapshot of the project at a particular point in time.
What is the staging area, also called the index?
An intermediate area holding the proposed content for the next commit.
What are the basic steps in Git’s everyday workflow?
Modify files, stage the changes, review the staged changes, and commit them to record a snapshot.
Why does Git have a staging area?
It lets you review and choose which changes belong in the next snapshot, so unrelated changes can be committed separately.
Does the staging area become empty after a commit?
No. After a commit, the staging area represents the same snapshot as the new commit until changes are staged.
What happens if you edit a file after staging it?
The staged snapshot remains unchanged, while the newer edit is an unstaged working-directory change; stage the file again to include that edit.
What happens when you delete a file from the working directory but have not staged the deletion?
The staged version remains in the staging area until you stage the deletion.
What does a Git commit contain, according to the material?
A unique identifier, information such as author and time, a message, and a complete snapshot of the project at that point.
Does Git store only the changes between snapshots?
The material explains that Git commits represent complete project snapshots rather than just deltas; Git stores data efficiently using compression and avoiding duplicate content.
What is the purpose of a commit message?
To explain what a snapshot represents and make the project history useful to you and your collaborators.
What does
git add .do?Stages changes throughout the current directory recursively, including new files; take care not to stage unwanted files.
How can you stage one file, several files, or matching files?
Use
git add <file>for one file, list multiple filenames separated by spaces, or use a pattern such asgit add '*.txt'for matching files.Are new files automatically tracked after
git init?No. New files are untracked until you add them to Git, typically with
git add.What does
git statusreport?The state of the working directory and staging area, including untracked, modified, and staged changes.
What does the
-moption do withgit commit?It supplies a commit message directly on the command line, as in
git commit -m "Initial commit".How do you create a commit message with a longer explanation?
Run
git commitwithout-m; Git opens the configured editor, where you can write a short subject followed by a blank line and a longer description.What are comment lines in a Git commit-message editor?
Lines beginning with
#; Git ignores them when creating the commit message.What is a common guideline for the length of a commit-message subject line?
Keep the short description ideally under 80 characters.
What makes a commit too small or too large?
A commit for every trivial file update is too small; waiting until an entire large feature or several days of work are finished can make it too large.
What should a well-sized commit represent?
A checkpoint containing one logically separate change set.
Why should unrelated changes, such as a typo fix and a bug fix, go in separate commits?
Separate commits keep each snapshot focused and make the project history easier to understand.
What makes a commit message useful?
It clearly and meaningfully describes the focused change represented by the commit.
Which tense is commonly used for Git commit messages in the material?
The present tense—for example, “Fix the bug.” Consistency within the team matters most.
How often should you commit?
Commit when the work reaches a meaningful state worth recording. Five to ten commits a day is only a rough real-world guideline, not a rule.
How can you commit modified files without separately staging them first?
Use
git commit -a -m "Message"(or combine the options asgit commit -am "Message"). This applies to modified tracked files, not arbitrary untracked files.When should you skip staging and use
git commit -a?Only when you are sure the changes do not need staging-area review; normally, stage and review changes before committing.
What does
git rm <file>do?Removes the file from both the working directory and the staging area.
What does
git mv <old> <new>do?Renames or moves a file and applies the change to both the working directory and the staging area.
How can a rename be staged if you rename a file using a regular system command instead of
git mv?Stage both the deletion of the old path and the addition of the new path; Git can recognize them as a rename.
What is a
.gitignorefile for, and where is it commonly placed?It lists files or directories Git should ignore; it is commonly placed at the root of the project.
How do you ignore a directory named
logsin.gitignore?Add the pattern
logs/.Why are generated binaries and log files often ignored?
They may be large, automatically generated, or specific to a developer, so tracking and sharing them can unnecessarily increase repository size.
Can adding an already tracked file to
.gitignoremake Git stop tracking it?No.
.gitignoredoes not affect files already tracked by Git; remove the file from the index first.How can you remove a tracked directory from the index while leaving it in the working directory?
Use
git rm --cached -r <directory>.--cachedremoves it from the index, and-rapplies recursively.What is the index in Git terminology?
Another name for the staging area.
Where can you find ready-made
.gitignorepatterns?In Git ignore templates for particular languages or project types; for example, Java templates commonly exclude generated
.classfiles and log files.What does
git status -sshow?A compact status summary using two status columns for each file.
In
git status -s, what do the left and right columns represent?The left column represents the staging area; the right column represents the working directory.
What does
??mean in short Git status output?The file is untracked.
What do
AandMindicate in short Git status output?Aindicates an added file;Mindicates a modified file. Their column position shows whether the change is staged or only in the working directory.What does
git ls-fileslist?The files currently in the index, or staging area.
What does
git diff --stagedshow?The staged changes—what is currently proposed for the next commit—compared with the last commit.
What does
git diffwith no arguments show?Unstaged changes in the working directory compared with the staging area.
What are the two versions compared by
git diff --staged?The old version from the last commit and the newer version currently in the staging area.
What are the two versions compared by
git diffwithout arguments?The old version in the staging area and the newer version in the working directory.
In a Git diff, what do minus and plus prefixes mean?
A minus line is from the old version or indicates removed content; a plus line is from the new version or indicates added content.
What is a diff hunk?
A section of a diff containing changed lines and surrounding context; its header describes the line ranges shown.
What does a diff header showing
0,0for the old file indicate?There were zero lines in the old version because the file did not exist in the previous commit; the file is new.
What does configuring
diff.tooldo?It names the visual diff tool Git should use; a separate tool command configuration tells Git how to launch it.
What does
git difftooldo, and how can it compare staged changes?It opens a configured visual tool to compare changes; add
--stagedto compare staged changes.Why review staged changes before committing?
To catch unwanted, incorrect, or broken changes before they become part of a permanent snapshot.
What does
git logdisplay by default?Commits in history, ordered from newest to oldest, with details such as identifier, author, date, and message.
What does
HEADidentify in Git?A reference to the current branch, indicating which branch is currently checked out.
What is a branch, and what does
masterrefer to in the material?A branch is a line of work;
masteris described as the main branch. Git branches let teams work on multiple features or fixes in parallel.What does
git log --onelineshow?A compact history with a shortened commit identifier and one-line commit message for each commit.
How do you display Git history from oldest commit to newest?
Use
git log --oneline --reverse.What is a Git commit identifier?
A unique 40-character hexadecimal identifier generated by Git for a commit; it is not a sequential revision number.
How can you refer to a commit by its identifier?
Use all or enough leading characters of its identifier to distinguish it from other commits.
What does
HEAD~1refer to?The commit one step before the commit currently referenced by
HEAD.What does
git show <commit>display?Details about the specified commit and a diff of what changed in it.
How can you view a file’s exact contents as stored in a particular commit?
Use
git show <commit>:<path>, such asgit show HEAD~1:.gitignore.What does
git ls-tree <commit>show?The files and directories in the specified commit’s tree.
How does Git represent files and directories in its object database?
Files are represented as blobs and directories as trees; commits are also objects, and tags are another kind of Git object.
What does
git show <object-id>let you inspect?An object in Git’s database, such as a commit, a file blob, or a directory tree.
What is the purpose of a tree object in Git?
It represents a directory and refers to its contents, which may include files and subdirectories.
How can you unstage a file with the restore command?
Use
git restore --staged <file>.What happens when you run
git restore --staged <file>?Git replaces the staged version with the version from the last commit, moving the staged changes back to the working directory.
What happens when you unstage a newly added file that is not in the last commit?
Git removes it from the staging area, and it becomes an untracked file again.
How can you discard unstaged changes to a tracked file?
Use
git restore <file>. Git replaces the working-directory version with the version in the staging area.How can you discard unstaged changes to all tracked files in the current directory?
Use
git restore ..Why can
git restorenot remove a new untracked file?Git has no earlier tracked version of that file to restore.
How can you remove untracked files, and what does
-fdo?Use
git clean -f;-fforces the removal because deleting untracked files can be irreversible.How can you remove untracked directories as well as files?
Use
git clean -fd;-dincludes directories and-fforces the operation.What command removes a file from both the working directory and staging area before committing its deletion?
git rm <file>.How can you restore a deleted file from the commit before the current one?
Use
git restore --source=HEAD~1 <file>.What does the
--sourceoption do withgit restore?It specifies which commit or source Git should use to restore the file, overriding the default source.
What is the default source for
git restorewhen restoring a working-directory file?The staging area.
What is the default source for
git restore --staged?The last commit.
What is the difference between restoring a file and undoing a commit?
Restoring a file replaces a file with a version from a chosen source; it does not itself undo the commit that recorded a change.

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