Practice Git branching operations with real-world scenarios
Interactive exercises to master Git branching and merging operations.
These exercises will help you master Git branching through practical scenarios. You'll work with multiple branches, handle merges, and resolve conflicts - all common tasks in real-world development.
You're working on a website project. Create feature branches to implement a navigation menu and a contact form, then merge them into the main branch.
- Create and switch to a branch for the navigation feature
- Make changes and commit them
- Create another branch for the contact form
- Make and commit changes on the contact form branch
- Merge both features into the main branch
Two team members have made different changes to the same file. Practice resolving the resulting merge conflict.
README.md
$ git add README.md $ git commit -m "Initial README"
$ git checkout -b feature/readme-update $ echo "# Project Title\nWelcome to our awesome project!" > README.md $ git commit -am "Update README welcome message"
$ git checkout main $ echo "# Project Title\nWelcome to our professional site." > README.md $ git commit -am "Update README messaging"`} />
>>>>>> feature/readme-update
Welcome to our awesome professional site!`} />
Practice branch management tasks including renaming, deleting, and listing branches. Also learn to visualize branch history.
- List all branches and their latest commits
- Rename a branch
- Delete merged branches
- Visualize branch history
Implement a feature-development-release branch pattern common in larger projects.
- Always create branches for new features or fixes, no matter how small
- Use descriptive branch names that reflect their purpose
- Regularly sync your feature branches with their base branch to avoid major
conflicts
- Delete branches after they're merged to keep your repository clean