| Command | Description | 
|---|---|
| git branch | Lists / creates and deletes branches | 
| git branch feature | Creates the featurebranch | 
| git branch -d feature | Deletes the featurebranch | 
| git switch | Switches between branches | 
| git switch feature | Switches to the featurebranch | 
| git checkout | Switches between branches | 
| git checkout -b feature | Creates and switches to the featurebranch | 
| git merge | Merges branches | 
| git merge feature | Merges the featurebranch into the current branch | 
| git merge --abort | Aborts a merge | 
| git merge --squash | Squaches commits on branch into a single commit and merge | 
| git stash | Stashes changes for later use | 
| git stash -m "stashing message" | Stashes changes and includes a message | 
| git stash list | Shows stored stashes | 
| git stash apply | Applies the latest stash | 
| git stash apply stash@{n} | Applies a specific stash | 
| git stash pop | Applies the latest stash and removes it from stash list | 
| git stash pop stash@{n} | Applies a specific stash and removes it from stash list | 
| git cherry-pick <commithash> | Applies changes from <commithash> | 
| git rebase | Different way of integrating changes from two branches | 
This session
In this session, you will work on the following tasks:
- Reading: Read the chapter(s) “Branches” in the Version Control Book.
- Implementation: Try out the commands in the chapter.
-  Exercises: Work on the exercises for the city-guideproject.
- Quiz: Test your knowledge with the quiz.
As always:
- Try out the commands of this session and play around with them.
- Check whether you have achieved the learning objectives.
- Ask questions!
- Let’s git started!
Learning objectives
💡 You understand the purpose and benefits of using branches in Git.
 💡 You can create and switch between branches.
 💡 You can merge branches and resolve merge conflicts.
 💡 You can name at least three best practices when working with branches.
city-guide project
At the end of this session, you should have accomplished the following:
- You created a new branch and merged changes into your default branch (mainormaster).
- You created and resolved a merge conflict.
Please keep the city-guide folder! We will continue to use it in the following sessions.
Exercises
Create and merge a new branch
- If needed, navigate to the project repository using the command line.
- Create a new branch called feature.
- Switch to the new branch.
- Add a new entry to your project text file.
- Stage and commit the changes to the project text file on the featurebranch.
- View the contents of project text file to verify your changes.
- Switch back to the default branch (mainormaster).
- View the contents of the project text file again to confirm that the previous changes do not exist on the default branch.
- Merge the featurebranch into your default branch.
- Delete the featurebranch.
- View the contents of project text file yet again to confirm that the previous changes have been merged into the default branch.
Create and resolve a merge conflict
- Deliberately create a merge conflict by editing the same section of a file on two separate branches and attempting to merge them. An example can be found in the branches chapter.
- Resolve the merge conflict.
- Delete the merged branch afterwards.
Slides
To print the slides to PDF, do the following:
- Toggle into Print View using the E key (or using the Navigation Menu).
- Open the in-browser print dialog (CTRL/CMD+P).
- Change the Destination setting to Save as PDF.
- Change the Layout to Landscape.
- Change the Margins to None.
- Enable the Background graphics option.
- Click Save.
Note: This feature has been confirmed to work in Google Chrome, Chromium as well as in Firefox.
Here’s what the Chrome print dialog would look like with these settings enabled:

These instructions were copied from the Quarto documentation (MIT License) and slightly modified.