Testing and Git · Part 18 of 36
Branches, pull requests and continuous integration
Intermediate 16 min
Branch, merge and rebase, resolve conflicts, review code in pull requests and let CI run your tests on every change.
What you will learn
- You can create, merge and delete branches.
- You can resolve a merge conflict.
- You can describe a pull-request workflow with CI checks.
Before this: Git: version control from the command line
Branches are cheap
A branch in Git is just a movable label pointing at a commit. Creating one costs almost nothing, so you make a branch for every feature or fix:
git switch -c fix-rounding # create and switch to a new branch
# … edit, add, commit …
git switch main
git merge fix-rounding # bring the work into main
git branch -d fix-rounding # delete the label
While you work on fix-rounding, main stays stable. If the idea fails, delete the branch; nothing else is affected.

Merging
If main has not moved since you branched, the merge is a fast-forward: Git simply moves the main label forward. If both branches have new commits, Git creates a merge commit with two parents, combining both lines of work.
Conflicts
When both branches changed the same lines, Git can't decide and marks a conflict in the file:
<<<<<<< HEAD
total = round(total, 2)
=======
total = math.floor(total * 100) / 100
>>>>>>> fix-rounding
You edit the file to the correct final version (it may combine both), delete the markers, then git add the file and git commit. Conflicts are normal; small branches that live only a day or two keep them rare and small.
Rebase
git rebase main replays your branch's commits on top of the newest main, giving a straight, linear history instead of merge commits. It rewrites your commits (new ids), so the golden rule applies: rebase only branches nobody else is using.
Pull requests and code review
On hosting platforms you push your branch and open a pull request (GitLab says merge request): a proposal to merge, with a description, the diff and a discussion. Teammates review it: they look for bugs, unclear names, missing tests and security issues, and comment line by line. Good reviews are kind and specific, and small pull requests get much better reviews than huge ones.
Continuous integration (CI)
CI runs automatically on every push and pull request: install dependencies, build, run linters and the whole test suite, maybe scan for vulnerable dependencies and leaked secrets. The pull request shows a green check or a red cross, and branch protection can block merging until checks pass and a reviewer approves. Continuous delivery/deployment (CD) goes further and ships every green main automatically.
CI pipelines are part of your software supply chain: they hold deployment credentials and produce the artefacts users install. NIST's Secure Software Development Framework (SP 800-218) and the OWASP Top 10:2025 category "Software Supply Chain Failures" both ask you to protect them like production: least privilege, pinned dependencies, reviewed changes, signed artefacts.
A typical day
git switch main && git pullgit switch -c feature-x- Small commits, tests green locally.
git push -u origin feature-x, open a pull request.- CI runs, a colleague reviews, you fix comments.
- Merge, delete the branch, deploy.
Key points
- A branch is a cheap, movable label; make one per feature or fix.
- Merges are fast-forward or create a merge commit; conflicts are resolved by editing and committing.
- Rebase gives linear history but rewrites commits — only on unshared branches.
- Pull requests combine the diff, discussion and review; keep them small.
- CI runs builds and tests on every change; protect pipelines as part of the supply chain.
Flashcards
- Question: What is a Git branch technically?
- Answer: A movable label (pointer) to a commit.
- Question: When is a merge a fast-forward?
- Answer: When the target branch has no new commits since you branched.
- Question: How do you finish resolving a conflict?
- Answer: Edit the file to its final form, remove markers, git add, then commit.
- Question: What does CI do on a pull request?
- Answer: Builds the code and runs tests and checks automatically, reporting pass/fail.
Check yourself
Think about your answer, then open it. In the app the quiz is interactive, earns points and brings back what you missed.
Which command creates a new branch and switches to it?
- git switch -c name
- git branch -d name
- git merge name
- git revert name
Show the answer
git switch -c name
switch -c creates and checks out a branch.
Source: Git reference, git-switch
When is rebasing a branch risky?
- When others have already pulled that branch
- When the branch is only on your laptop
- When the branch has one commit
- Never
Show the answer
When others have already pulled that branch
Rebase rewrites commit ids; collaborators would have diverging histories.
Source: Pro Git, 3.6 Rebasing
Order a typical pull-request workflow.
Show the answer
Create a branch → Commit and push → Open a pull request → CI and review pass → Merge
Work on a branch, propose it, get checks and review, then merge.
Source: Pro Git, 6.2
Which belong in a CI pipeline?
- Running the test suite
- Running linters
- Scanning dependencies for known vulnerabilities
- Printing deployment secrets into the log
Show the answer
Running the test suite; Running linters; Scanning dependencies for known vulnerabilities
Secrets must never be printed; the other steps are standard CI checks.
Source: NIST SP 800-218
Sources
- Pro Git (2nd ed.), Scott Chacon & Ben Straub, Apress, 2014 (online edition updated)
- Git reference documentation: git-merge, git-rebase, git-switch, git-scm.com, 2025
- NIST SP 800-218 Secure Software Development Framework (SSDF) 1.1, NIST, 2022
Facts checked on 2026-11-30. Skillgrove lessons are free learning material — no certificate and no accreditation.