🌍 Git & Version Control · subject

Git & Version Control Best Practices and Troubleshooting Syllabus

The Best Practices and Troubleshooting syllabus for Git & Version Control in full: 4 chapters and 14 topics, every one listed below, plus 50 Best Practices and Troubleshooting flashcards with answers.

4Chapters
14Topics
50Flashcards

Best Practices and Troubleshooting syllabus: all 4 chapters

Expand any chapter to see its topics and sub-topics.

  1. Repository Hygiene

    4 topics
    • Effective .gitignore and .gitattributes
    • Keeping a Clean History
    • Atomic Commits
    • Documentation and README Standards
  2. Common Problems and Recovery

    4 topics
    • Recovering Deleted Branches and Commits
    • Fixing Detached HEAD State
    • Undoing a Bad Merge or Rebase
    • Resolving Diverged Branches
  3. Workflows for Different Team Sizes

    3 topics
    • Solo Developer Workflow
    • Small Team Workflow
    • Large Enterprise Workflows
  4. Migration and Interoperability

    3 topics
    • Migrating from SVN to Git
    • Importing and Exporting Repositories
    • Mirroring and Backups

Git & Version Control Best Practices and Troubleshooting flashcards — 50 questions with answers

  1. What is the primary purpose of a .gitignore file?

    To tell Git which intentionally untracked files or directories to ignore, preventing them from being staged or committed (e.g., build artifacts, logs, dependency folders, secrets).

  2. How does .gitattributes differ in purpose from .gitignore?

    .gitignore excludes files from tracking, while .gitattributes defines per-path behaviors for tracked files, such as line-ending normalization, diff/merge strategies, export handling, and Git LFS filters.

  3. In .gitignore syntax, what does a leading slash (e.g., /build) signify?

    It anchors the pattern to the directory containing the .gitignore file, matching only at that root level rather than in any subdirectory.

  4. In .gitignore, what is the effect of a trailing slash (e.g., logs/)?

    It matches only directories named 'logs' (and their contents), not files with that name.

  5. How do you re-include a file that was previously excluded by a broader .gitignore pattern?

    Use a negation pattern with a leading exclamation mark, e.g., '!important.log', though a file cannot be re-included if its parent directory is excluded.

  6. Why does adding a pattern to .gitignore fail to remove a file that is already tracked?

    .gitignore only affects untracked files; an already-tracked file must first be removed from the index with 'git rm --cached <file>' and then committed.

  7. Which .gitattributes setting normalizes line endings, and what does it do?

    '* text=auto' tells Git to auto-detect text files and store them with LF line endings in the repository while checking them out with the platform's native endings.

  8. How do you mark a file as binary in .gitattributes, and what is the effect?

    Use '<pattern> binary' (shorthand for '-text -diff'); Git will not attempt line-ending conversion or textual diffs on that file.

  9. What does the 'export-ignore' attribute in .gitattributes do?

    It excludes the matching paths from archives produced by 'git archive' (e.g., omitting tests or CI files from a release tarball).

  10. Define an 'atomic commit' in Git best practice.

    A commit that represents one complete, self-contained logical change—it does exactly one thing, builds/passes on its own, and can be reverted independently without breaking unrelated functionality.

  11. List three benefits of making atomic commits.

    Easier code review, cleaner and more meaningful history, and simpler debugging via 'git bisect' or targeted 'git revert' of a single change.

  12. Which Git command lets you stage only selected portions (hunks) of a file to build an atomic commit?

    'git add -p' (or 'git add --patch'), which interactively presents each hunk to stage, split, or skip.

  13. What are the conventional structural components of a good commit message?

    A concise imperative subject line (about 50 characters or fewer), a blank line, and a body wrapped near 72 characters explaining the what and why of the change.

  14. What does 'keeping a clean history' mean, and name two techniques to achieve it.

    It means a linear, readable, logically ordered commit history. Techniques: interactive rebase to squash/reorder/reword commits ('git rebase -i') and rebasing feature branches onto main instead of merging.

  15. What is the golden rule of rebasing regarding shared branches?

    Never rebase (or rewrite history of) commits that have been pushed to a shared/public branch others may have based work on, because it rewrites hashes and diverges everyone's history.

  16. What is the difference between 'git merge' and 'git rebase' for integrating changes?

    Merge creates a new merge commit joining two histories, preserving branch topology; rebase replays your commits on top of another base, producing a linear history but rewriting commit hashes.

  17. What is a fast-forward merge, and when does it occur?

    A merge where the target branch has no new commits since the branch diverged, so Git simply moves the branch pointer forward to the tip of the merged branch—no merge commit is created.

  18. What should a good README document at minimum?

    Project name/description, installation/setup instructions, usage examples, configuration, contribution guidelines, license, and how to run tests—so a newcomer can understand and use the project quickly.

  19. What lightweight markup language is conventionally used for README files on platforms like GitHub?

    Markdown (README.md).

  20. What is the purpose of Conventional Commits, and give an example prefix.

    A specification standardizing commit message format to enable automated changelog generation and semantic versioning; example prefixes include 'feat:', 'fix:', 'docs:', 'refactor:', and 'chore:'.

Show the other 30 Best Practices and Troubleshooting flashcards
  1. How can you recover a branch you accidentally deleted in Git?

    Find the branch tip's commit hash using 'git reflog', then recreate the branch with 'git branch <name> <hash>' (or 'git checkout -b <name> <hash>').

  2. What is the Git reflog, and why is it key to recovery?

    The reflog is a local log recording every update to branch tips and HEAD; it lets you find and restore commits or branches that are no longer referenced by any branch, before garbage collection removes them.

  3. How long does Git typically retain unreachable objects before garbage collection, by default?

    Reachable-from-reflog entries expire after about 90 days, and unreachable objects after about 30 days (gc.reflogExpire and gc.pruneExpire defaults).

  4. How do you recover a specific deleted commit whose hash you found in the reflog?

    Reset or cherry-pick it: 'git reset --hard <hash>' to move the current branch back to it, or 'git cherry-pick <hash>' to reapply it onto the current branch.

  5. What is a 'detached HEAD' state in Git?

    A state where HEAD points directly at a specific commit rather than at a branch reference, so new commits are not attached to any branch and can be lost if you switch away.

  6. How do you typically enter a detached HEAD state?

    By checking out a specific commit, tag, or remote-tracking ref directly, e.g., 'git checkout <commit-hash>' or 'git checkout v1.0'.

  7. How do you preserve work made in a detached HEAD state?

    Create a branch pointing to the current commit before switching away: 'git switch -c <new-branch>' (or 'git branch <name>' followed by checkout).

  8. How do you leave a detached HEAD without keeping any new commits?

    Simply check out an existing branch, e.g., 'git switch main' (or 'git checkout main'); the detached commits become unreferenced.

  9. How do you undo a merge that has NOT yet been pushed or shared?

    Use 'git reset --hard ORIG_HEAD' (or the pre-merge commit hash) to move the branch back to its state before the merge.

  10. How do you safely undo a bad merge that has already been pushed to a shared branch?

    Use 'git revert -m 1 <merge-commit-hash>', which creates a new commit reversing the merge while preserving history; '-m 1' selects the mainline parent.

  11. Why does reverting a merge commit require the '-m' (mainline) option?

    Because a merge commit has two parents, Git cannot infer which parent's state to revert to, so '-m <parent-number>' specifies which parent line to keep as the mainline.

  12. How do you abort a rebase that is in progress and running into conflicts?

    Run 'git rebase --abort', which restores the branch to its original state before the rebase started.

  13. How can you undo a rebase that has already completed, returning to the pre-rebase state?

    Use the reflog to find the pre-rebase tip and reset to it: 'git reset --hard HEAD@{n}' (or the specific hash shown before the rebase).

  14. What does it mean for two branches to have 'diverged'?

    Both the local and remote (or two) branches have unique commits the other lacks since their common ancestor, so neither can be fast-forwarded to the other.

  15. What are the two main strategies to reconcile a diverged local and remote branch during a pull?

    Merge ('git pull --no-rebase', creating a merge commit) or rebase ('git pull --rebase', replaying local commits on top of the remote tip).

  16. After branches diverge, why can a 'git push' be rejected, and what is the safe fix?

    The push is rejected because the remote has commits you lack (non-fast-forward). The safe fix is to integrate remote changes first via 'git pull --rebase' (or merge), then push—avoid blind force-push.

  17. What is the safer alternative to 'git push --force' when updating a rewritten branch, and why?

    'git push --force-with-lease', which refuses to overwrite the remote if it has been updated since you last fetched, protecting against clobbering others' commits.

  18. Describe a typical solo developer Git workflow.

    Often a single main branch (or short-lived feature branches) with direct commits, frequent local commits, optional rebasing to keep history clean, and pushing to a single remote for backup—minimal ceremony since there is no review process.

  19. Describe the core of a small team Git workflow (feature branch / GitHub Flow).

    Each feature is developed on a short-lived branch off main, opened as a pull request for review and CI, then merged back to a always-deployable main; releases come directly from main.

  20. What is Git Flow, and what long-lived branches does it define?

    A branching model for scheduled releases using two permanent branches—'main' (production) and 'develop' (integration)—plus supporting 'feature/', 'release/', and 'hotfix/' branches.

  21. Compare trunk-based development with Git Flow for enterprise scale.

    Trunk-based development keeps all developers committing to a single main trunk with very short-lived branches and feature flags, favoring continuous integration; Git Flow uses multiple long-lived branches suited to versioned, scheduled releases but adds merge overhead.

  22. What is the 'forking workflow' commonly used in large open-source/enterprise projects?

    Each contributor forks the central repository into their own copy, pushes to their fork, and submits pull requests to the upstream; maintainers review and merge, keeping the canonical repo protected from direct pushes.

  23. What are protected branches and branch protection rules in enterprise workflows?

    Rules on key branches (e.g., main) that enforce policies like required reviews, passing status checks, up-to-date branches, signed commits, and disallowing force-pushes or deletions before merging.

  24. Which tool is the standard bidirectional bridge for migrating from SVN to Git?

    'git svn', which can clone an SVN repository into Git and sync commits in both directions.

  25. What does 'git svn clone -s <url>' do, and what does the '-s' flag assume?

    It clones an SVN repository into a Git repo; '-s' (--stdlayout) assumes the standard SVN layout of trunk/, branches/, and tags/ directories.

  26. Why is an authors mapping file important when migrating from SVN to Git?

    SVN records only usernames, so an authors file maps each SVN username to a proper Git 'Name <email>' identity, ensuring correct attribution in the migrated history.

  27. How do you create a portable bundle of a repository for import/export or transfer without a network remote?

    Use 'git bundle create <file.bundle> <refs>' to package commits into a single file, then clone or fetch from it with 'git clone <file.bundle>' or 'git fetch <file.bundle>'.

  28. What is the difference between a normal 'git clone' and 'git clone --mirror'?

    A normal clone copies the default branch and sets up a working tree; '--mirror' creates a bare repository copying all refs (branches, tags, remotes) exactly and configures it to mirror the source for backups.

  29. How do you keep a mirror backup repository up to date with its source?

    In the bare mirror clone, run 'git remote update' (or 'git fetch --all') periodically; combined with 'git push --mirror' you can also propagate to another remote.

  30. What is the difference between a bare and a non-bare Git repository, and where is each used?

    A bare repository (created with 'git init --bare') has no working directory and stores only the Git data; it is used as a shared/central remote and for mirrors/backups, whereas a non-bare repo has a checked-out working tree for development.

Git & Version Control Best Practices and Troubleshooting FAQ

What is in the Git & Version Control Best Practices and Troubleshooting syllabus?

Git & Version Control Best Practices and Troubleshooting is split into 4 chapters: Repository Hygiene, Common Problems and Recovery, Workflows for Different Team Sizes and Migration and Interoperability. Together they contain 14 topics.

How many chapters are in Git & Version Control Best Practices and Troubleshooting?

4 chapters, containing 14 topics. The largest chapter is Repository Hygiene, with 4 topics.

Are there flashcards for Git & Version Control Best Practices and Troubleshooting?

Yes — a 50-card Best Practices and Troubleshooting deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.