0
0
Gitdevops~30 mins

Merge strategies overview in Git - Mini Project: Build & Apply

Choose your learning style9 modes available
Merge strategies overview
📖 Scenario: You are working on a project with two branches: main and feature. You want to learn how to combine changes from feature into main using different merge strategies in Git.
🎯 Goal: Learn how to use three common Git merge strategies: merge, rebase, and fast-forward. You will practice creating branches, making commits, and applying these merge strategies step-by-step.
📋 What You'll Learn
Create a Git repository with two branches: main and feature
Make commits on both branches
Use git merge to combine branches with a merge commit
Use git rebase to replay commits from one branch onto another
Use git merge --ff-only to perform a fast-forward merge
💡 Why This Matters
🌍 Real World
In real projects, developers use different merge strategies to keep the project history clean and understandable. Knowing when to use merge commits, rebase, or fast-forward merges helps teams collaborate smoothly.
💼 Career
Understanding Git merge strategies is essential for software developers, DevOps engineers, and anyone working with version control. It helps in managing code changes, collaborating with teams, and maintaining a clear project history.
Progress0 / 4 steps
1
Setup initial Git repository and branches
Initialize a Git repository. Create a file named README.md with the content Initial commit. Commit this file on the main branch. Then create a new branch called feature from main.
Git
Need a hint?

Use git init to start the repo. Use echo to create the file. Use git add and git commit to save changes. Use git branch feature to create the branch.

2
Make commits on both branches
Switch to the feature branch. Create a file named feature.txt with the content Feature work. Commit this change. Then switch back to main and create a file named main.txt with the content Main work. Commit this change.
Git
Need a hint?

Use git checkout feature to switch branches. Create and commit files on each branch separately.

3
Merge feature into main with a merge commit
Switch to the main branch. Use git merge feature to merge the feature branch into main creating a merge commit.
Git
Need a hint?

Make sure you are on main branch before merging. Use git merge feature to combine branches with a merge commit.

4
Rebase feature onto main and fast-forward merge
Reset your repository to the state before the merge commit. Switch to feature branch. Use git rebase main to replay feature commits on top of main. Then switch to main and use git merge --ff-only feature to fast-forward merge feature into main.
Git
Need a hint?

Use git reset --hard HEAD~1 to undo the merge commit. Use git rebase main on feature. Then fast-forward merge with git merge --ff-only feature.