Use branches and pull requests
Learn how branches isolate proposed work and pull requests make it reviewable on GitHub.
A branch is a movable name for work
A branch lets you develop a change separately from another line of work. In Git, a branch is a lightweight reference to a commit. Creating a branch does not copy the entire project; it gives you a separate name that can advance as you add commits.
git switch -c <branch-name>
git switch -c creates a branch and checks it out, making it the current branch. New commits then advance that branch. Use git status to see which branch is active. Return to the main line with git switch main when the activity calls for it.
For the two-lead activity, both branches must begin from the same published main commit. The app gives you the correct order and branch names. Starting each branch from the same base makes the proposed changes independent and makes their later comparison meaningful.
Publish a branch
git push -u origin <branch-name>
Each branch is local until pushed. Publishing it makes that branch available in your GitHub repository. The -u option connects the local branch to its remote counterpart, so later pushes can omit the destination.
Branches are separate lines of history, but they share commits up to their common starting point. This is why two changes can be prepared independently and reviewed before either is incorporated into main.
A pull request is a review proposal
A pull request (PR) is a GitHub conversation about merging one branch into another. It is not a Git command. The base is the branch that would receive the changes, and the compare branch is the branch containing the proposed work. In this workshop, each lead branch proposes changes to your repository’s main.
GitHub shows the difference between the branches, lets you discuss and review the change, and then offers merge options when the PR is ready. Review the file diff before merging. Keep both workshop pull requests open until the activity asks you to merge the first one; their order is part of the exercise.
After a pull request is merged, the target branch advances. Another branch based on the earlier version may need to incorporate the new main before GitHub can merge it. That is the situation you will resolve in the next section.