4.1 Practical
Branching, merging, and pull requests
In this practical, you’ll create a new branch, make some changes, and then merge those changes back using GitHub’s web interface.
Our branching workflow
Remember the branching process:
- We create a new
branchfrom main (git branch <branch-name>) - We
switchto our new branch (git checkout <branch-name>orgit switch <branch-name>) - We make changes,
add, andcommitas usual - We *
pushour branch to GitHub (git push origin <branch-name>) - We create a
pull requeston GitHub to merge our changes - We
mergethe pull request anddeletethe branch
Step 1: Create and switch to a new branch
Check your current branch and status:
git status git branchCreate a new branch called
feature-bio:git branch feature-bioSwitch to your new branch:
git checkout feature-bioOr use the newer syntax:
git switch feature-bioVerify you’re on the new branch:
git branchYou should see an asterisk () next to
feature-bio*
You can create and switch to a new branch in one command: git checkout -b feature-bio or git switch -c feature-bio
Step 2: Make changes on your branch
Create a new file called
about.md:touch about.mdEdit the file and add some content about yourself:
# About Me ## Bio Write a few sentences about yourself here. ## Research Interests - List your research areas - Or hobbies if you prefer! ## Fun Fact Share something interesting about yourself.Add and commit your changes:
git add about.md git commit -m "Add personal bio page"
Step 3: Push your branch to GitHub
Push your branch to GitHub:
git push origin feature-bioCheck the output - git will give you a link to create a pull request!
Step 4: Create a pull request on GitHub
Go to your repository on GitHub in your browser
You should see a yellow banner saying “Compare & pull request” - click it!
If you don’t see it:
- Click the “Branch” dropdown and select
feature-bio - Click “Contribute” → “Open pull request”
- Click the “Branch” dropdown and select
Fill in the pull request details:
- Title: Something descriptive like “Add personal bio page”
- Description: Explain what changes you made
- Review the changes in the “Files changed” tab
Click “Create pull request”
Step 5: Review and merge the pull request
- Review your pull request:
- Check the “Files changed” tab to see your modifications
- Look at the “Checks” (if any are running)
- Merge the pull request:
- Click “Merge pull request”
- Click “Confirm merge”
- Optionally click “Delete branch” to clean up
Step 6: Update your local repository
Switch back to main branch:
git checkout mainPull the latest changes:
git pull origin mainVerify your changes are now in main:
ls cat about.mdClean up your local branch (optional):
git branch -d feature-bio
- Use
git branchto list all branches - Use
git branch <name>to create a new branch - Use
git checkout <name>orgit switch <name>to switch branches - Use
git push origin <branch-name>to push a branch to GitHub - Always create pull requests for important changes - even when working alone!
- Pull requests provide a record of what changed and why
Challenge: Try it again!
Create another branch, make different changes (maybe edit your README.md), and go through the pull request process again!