1. Home
  2. Explore
  3. Computer Science
  4. Git Fundamentals

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Git Fundamentals

  • 111Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Version Control
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is a version control system?

Tap to flipClick to flipspace

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

  1. 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.

  2. 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.

  3. 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.

  4. What are the two broad categories of version control systems?

    Centralized and distributed version control systems.

  5. How does a centralized version control system work?

    Team members connect to a central server to obtain the latest code and share their changes.

  6. 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.

  7. 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.

  8. Name two centralized and two distributed version control systems.

    Subversion and Microsoft Team Foundation Server (TFS) are centralized; Git and Mercurial are distributed.

  9. 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.

  10. 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.

  11. 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.

  12. 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.

  13. 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.

  14. 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.

  15. What does git --version do?

    Displays the installed Git version.

  16. 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.

  17. Which Git configuration level should you use for a preference that applies to all your repositories?

    The global level, specified with git config --global.

  18. How do you configure your Git username globally?

    Use git config --global user.name "Your Name". Quotes are needed when the value contains spaces.

  19. 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.

  20. How do you configure VS Code as Git’s default editor, and what does --wait do?

    Set core.editor to code --wait; --wait makes the terminal wait until the VS Code window is closed.

  21. How can you edit your global Git configuration in the default editor?

    Run git config --global --edit.

  22. Where are Git configuration settings stored, and how are they organized?

    In a text file named .gitconfig; settings are organized into sections such as user and core.

  23. 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).

  24. What does Git’s core.autocrlf setting control?

    How Git handles line endings when checking files out of or storing them in the repository.

  25. What core.autocrlf value 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.

  26. What core.autocrlf value 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.

  27. How can you get full documentation for a Git command from the terminal?

    Run git <command> --help, such as git config --help; press Space to page through and q to quit.

  28. How can you get a brief summary of a Git command’s options?

    Run git <command> -h, such as git config -h.

  29. What does git init do?

    Initializes an empty Git repository in the current project directory by creating a .git subdirectory.

  30. What is the .git directory for?

    It stores Git’s information about the repository and project history.

  31. Why should you avoid manually deleting or changing the .git directory?

    It contains the repository’s history and data; removing it causes the project to lose its Git repository and history.

  32. Why might ls not show the .git directory, and how can you list it?

    It is hidden by default. Use ls -a to show hidden files and directories.

  33. What is a Git commit?

    A recorded snapshot of the project at a particular point in time.

  34. What is the staging area, also called the index?

    An intermediate area holding the proposed content for the next commit.

  35. 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.

  36. 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.

  37. 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.

  38. 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.

  39. 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.

  40. 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.

  41. 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.

  42. 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.

  43. What does git add . do?

    Stages changes throughout the current directory recursively, including new files; take care not to stage unwanted files.

  44. 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 as git add '*.txt' for matching files.

  45. Are new files automatically tracked after git init?

    No. New files are untracked until you add them to Git, typically with git add.

  46. What does git status report?

    The state of the working directory and staging area, including untracked, modified, and staged changes.

  47. What does the -m option do with git commit?

    It supplies a commit message directly on the command line, as in git commit -m "Initial commit".

  48. How do you create a commit message with a longer explanation?

    Run git commit without -m; Git opens the configured editor, where you can write a short subject followed by a blank line and a longer description.

  49. What are comment lines in a Git commit-message editor?

    Lines beginning with #; Git ignores them when creating the commit message.

  50. What is a common guideline for the length of a commit-message subject line?

    Keep the short description ideally under 80 characters.

  51. 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.

  52. What should a well-sized commit represent?

    A checkpoint containing one logically separate change set.

  53. 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.

  54. What makes a commit message useful?

    It clearly and meaningfully describes the focused change represented by the commit.

  55. 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.

  56. 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.

  57. How can you commit modified files without separately staging them first?

    Use git commit -a -m "Message" (or combine the options as git commit -am "Message"). This applies to modified tracked files, not arbitrary untracked files.

  58. 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.

  59. What does git rm <file> do?

    Removes the file from both the working directory and the staging area.

  60. 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.

  61. 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.

  62. What is a .gitignore file 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.

  63. How do you ignore a directory named logs in .gitignore?

    Add the pattern logs/.

  64. 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.

  65. Can adding an already tracked file to .gitignore make Git stop tracking it?

    No. .gitignore does not affect files already tracked by Git; remove the file from the index first.

  66. How can you remove a tracked directory from the index while leaving it in the working directory?

    Use git rm --cached -r <directory>. --cached removes it from the index, and -r applies recursively.

  67. What is the index in Git terminology?

    Another name for the staging area.

  68. Where can you find ready-made .gitignore patterns?

    In Git ignore templates for particular languages or project types; for example, Java templates commonly exclude generated .class files and log files.

  69. What does git status -s show?

    A compact status summary using two status columns for each file.

  70. 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.

  71. What does ?? mean in short Git status output?

    The file is untracked.

  72. What do A and M indicate in short Git status output?

    A indicates an added file; M indicates a modified file. Their column position shows whether the change is staged or only in the working directory.

  73. What does git ls-files list?

    The files currently in the index, or staging area.

  74. What does git diff --staged show?

    The staged changes—what is currently proposed for the next commit—compared with the last commit.

  75. What does git diff with no arguments show?

    Unstaged changes in the working directory compared with the staging area.

  76. 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.

  77. What are the two versions compared by git diff without arguments?

    The old version in the staging area and the newer version in the working directory.

  78. 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.

  79. What is a diff hunk?

    A section of a diff containing changed lines and surrounding context; its header describes the line ranges shown.

  80. What does a diff header showing 0,0 for 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.

  81. What does configuring diff.tool do?

    It names the visual diff tool Git should use; a separate tool command configuration tells Git how to launch it.

  82. What does git difftool do, and how can it compare staged changes?

    It opens a configured visual tool to compare changes; add --staged to compare staged changes.

  83. Why review staged changes before committing?

    To catch unwanted, incorrect, or broken changes before they become part of a permanent snapshot.

  84. What does git log display by default?

    Commits in history, ordered from newest to oldest, with details such as identifier, author, date, and message.

  85. What does HEAD identify in Git?

    A reference to the current branch, indicating which branch is currently checked out.

  86. What is a branch, and what does master refer to in the material?

    A branch is a line of work; master is described as the main branch. Git branches let teams work on multiple features or fixes in parallel.

  87. What does git log --oneline show?

    A compact history with a shortened commit identifier and one-line commit message for each commit.

  88. How do you display Git history from oldest commit to newest?

    Use git log --oneline --reverse.

  89. 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.

  90. 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.

  91. What does HEAD~1 refer to?

    The commit one step before the commit currently referenced by HEAD.

  92. What does git show <commit> display?

    Details about the specified commit and a diff of what changed in it.

  93. How can you view a file’s exact contents as stored in a particular commit?

    Use git show <commit>:<path>, such as git show HEAD~1:.gitignore.

  94. What does git ls-tree <commit> show?

    The files and directories in the specified commit’s tree.

  95. 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.

  96. 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.

  97. 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.

  98. How can you unstage a file with the restore command?

    Use git restore --staged <file>.

  99. 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.

  100. 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.

  101. 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.

  102. How can you discard unstaged changes to all tracked files in the current directory?

    Use git restore ..

  103. Why can git restore not remove a new untracked file?

    Git has no earlier tracked version of that file to restore.

  104. How can you remove untracked files, and what does -f do?

    Use git clean -f; -f forces the removal because deleting untracked files can be irreversible.

  105. How can you remove untracked directories as well as files?

    Use git clean -fd; -d includes directories and -f forces the operation.

  106. What command removes a file from both the working directory and staging area before committing its deletion?

    git rm <file>.

  107. How can you restore a deleted file from the commit before the current one?

    Use git restore --source=HEAD~1 <file>.

  108. What does the --source option do with git restore?

    It specifies which commit or source Git should use to restore the file, overriding the default source.

  109. What is the default source for git restore when restoring a working-directory file?

    The staging area.

  110. What is the default source for git restore --staged?

    The last commit.

  111. 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.

Card 1 of 111
Card 1 of 111

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent