🐍 Python for Everyone

← Back to exercises

Chapter 28 Practice Bank 70-90 min, hands-on

Practice Bank: Git Fundamentals

A deeper set of practice problems, organized by topic, for extra reps beyond the main exercises — including scenario-based problems written in the same style you'll meet in real interviews. This chapter teaches git itself, not just Python syntax, so every problem here is a Python function that simulates or reasons about a git concept using plain data standing in for a repo's history. Standard library only — no installs needed.

Why simulate git instead of running it? This site runs your code in a browser sandbox with no real git installed, so every problem models a git concept as a Python function over plain data (lists of commit ids, booleans for branch state, strings for file content) instead of literally shelling out to git. Every behavior these problems describe was checked against real git in a scratch repository first — the semantics are genuinely correct, just expressed in Python so they can be auto-graded. To practice the real commands, install git and follow along with this chapter's lesson in an actual terminal.
How to run these Download starter.py below and run python3 starter.py from inside the same folder. Standard library only — nothing to install.

Topic 1: Why Version Control Matters

1 Counting manual "backup" files

Find # TODO 1.1. Write count_versions_without_git(filenames).

2 Can two people edit safely?

Find # TODO 1.2. Write can_two_people_edit_safely(uses_git).

3 Debug the Code

Find # TODO 1.3. This wrongly claims git only tracks the current file state, like a shared folder. Fix it.

💼 Scenario

Comparing Two Approaches

Find # TODO 1.A. Write safer_collaboration_choice(team_size, needs_history).

💼 Interview Prep

Why version control matters

Find # TODO 1.B. Write explain_why_version_control_matters().

Topic 2: The Core Git Workflow (init, add, commit, status, diff, log, staging area)

1 What's staged?

Find # TODO 2.1. Write files_in_staging_area(added_files, committed_files).

2 Is the working tree clean?

Find # TODO 2.2. Write is_working_tree_clean(staged, unstaged).

3 Debug the Code

Find # TODO 2.3. This wrongly claims git add immediately and permanently commits a file. Fix it.

💼 Scenario

Comparing Two Approaches

Find # TODO 2.A. Write should_run_status_first(has_uncommitted_changes).

💼 Interview Prep

Why add and commit are separate

Find # TODO 2.B. Write explain_add_then_commit().

Topic 3: Branching (create/switch/delete, branch-as-pointer)

1 Where a new branch starts

Find # TODO 3.1. Write new_branch_points_to(current_commit).

2 A branch pointer advancing

Find # TODO 3.2. Write commits_on_branch_after(history, branch_start_commit, new_commits).

3 Debug the Code

Find # TODO 3.3. This wrongly claims deleting a branch instantly erases its commits forever. Fix it.

💼 Scenario

Comparing Two Approaches

Find # TODO 3.A. Write should_delete_branch(is_merged, still_needed).

💼 Interview Prep

Branch as a movable pointer

Find # TODO 3.B. Write explain_branch_as_pointer().

Topic 4: Merging (fast-forward vs. three-way, merge commits, resolving conflicts)

1 Is a fast-forward possible?

Find # TODO 4.1. Write is_fast_forward_possible(target_branch_commits, source_branch_commits).

2 Does the merge create a commit?

Find # TODO 4.2. Write merge_creates_commit(is_fast_forward).

3 Debug the Code

Find # TODO 4.3. This has the HEAD/incoming conflict marker order backwards. Fix it.

💼 Scenario

Comparing Two Approaches

Find # TODO 4.A. Write predict_merge_type(target_has_new_commits).

💼 Interview Prep

Resolving a real conflict

Find # TODO 4.B. Write explain_resolving_a_conflict().

Topic 5: Rebase (vs. merge, interactive rebase basics, don't rebase shared history)

1 Rebase gives a linear history

Find # TODO 5.1. Write rebase_result_is_linear().

2 Rebased commits get new hashes

Find # TODO 5.2. Write commit_hashes_change_after_rebase(original_hashes).

3 Debug the Code

Find # TODO 5.3. This always says it's safe to rebase, even a shared branch. Fix it.

💼 Scenario

Comparing Two Approaches

Find # TODO 5.A. Write choose_merge_or_rebase(branch_is_shared, wants_linear_history).

💼 Interview Prep

Why not rebase shared history

Find # TODO 5.B. Write explain_why_not_rebase_shared_history().

Topic 6: Undoing Things Safely (checkout/restore vs. reset vs. revert, stashing, reflog)

1 Revert adds a commit

Find # TODO 6.1. Write revert_keeps_history_length(original_commit_count).

2 Reset --hard shortens the log

Find # TODO 6.2. Write reset_hard_removes_from_log(original_commit_count, commits_reset_away).

3 Debug the Code

Find # TODO 6.3. This always recommends reset, even for a commit that's already been pushed and shared. Fix it.

💼 Scenario

Recovering "Lost" Work

Find # TODO 6.A. Write can_recover_after_hard_reset(reflog_still_has_entry).

💼 Interview Prep

reset vs. revert

Find # TODO 6.B. Write explain_reset_vs_revert().

Checking your work Compare your output against solution.py. Your exact wording doesn't need to match on the explanation-style tasks — the goal is that your program runs without errors and does what each TODO asks. Every data-driven task's output is exactly reproducible.
← Exercises Challenges →