0% complete

Git & GitHub for Data Analysts · Lesson 2 of 3

Branches, Pull Requests, and Merge Conflicts

Collaborate on analysis work through isolated branches and deliberate reviews.

Lesson

1. Introduction

Branches let analysts develop a report or transformation without changing the shared main line immediately. Pull requests create a place to review code, assumptions, and tests before combining work.

2. Understand the concept

A branch points to a line of commits. A merge combines histories; a conflict occurs when Git cannot safely choose between concurrent edits. Notebook files can be difficult to review as plain text, so keep complex calculations in versioned source modules when appropriate.

3. Syntax and interpretation

git switch -c add-region-metrics
git status
git add src/metrics.py
git commit -m "Add regional metrics"
git push -u origin add-region-metrics

The branch keeps the change isolated and the upstream setting lets later pushes use the same remote branch.

4. Apply it to an analysis

Collaborate on analysis work through isolated branches and deliberate reviews. Start with a small, known example and state what each row or value represents. After the transformation, check row counts, types, keys, and units against the original data. If an assumption fails, stop and investigate instead of presenting the output as a valid result.

5. Common mistakes

  • Resolving a conflict by accepting one side without checking the analytical meaning.
  • Force-pushing shared history without coordination.

6. Practice task

A teammate changes the denominator definition while you change the numerator. What should reviewers verify?

7. One possible solution

Review the combined metric definition and ensure numerator and denominator use the same population, time window, and inclusion rules.

8. Summary and next step

Collaborate on analysis work through isolated branches and deliberate reviews. Continue to the next course section and apply this foundation to a different analytics tool or workflow.

Visual guide

Working through Branches, Pull Requests, and Merge Conflicts

  1. Step 01 Define

    State the question, data grain, and expected output.

  2. Step 02 Apply

    Use the method and check its assumptions on a small example.

  3. Step 03 Verify

    Reconcile the result and communicate limitations.

Code examples

Resolve a conflict intentionally
TEXT
1. Open the conflicted file and compare both edits.\n2. Keep the intended logic and remove conflict markers.\n3. Run tests and inspect the final diff.\n4. Stage the resolved file and commit.
Expected output
A resolution preserves the intended behavior from both collaborators.
Review before merging
TEXT
Check: metric definition, data assumptions, tests, sample outputs, privacy, and environment instructions.
Expected output
A review considers analytical correctness as well as code style.

Key points

  • Collaborate on analysis work through isolated branches and deliberate reviews.
  • Check the result against the stated data definition and a representative example.
  • Record assumptions and report data-quality limitations rather than hiding them.

Check your understanding

Practice

Which approach best applies the ideas in Branches, Pull Requests, and Merge Conflicts?

Your learning progress

Finish this lesson