0
0
Gitdevops~30 mins

Three-way merge in Git - Mini Project: Build & Apply

Choose your learning style9 modes available
Three-way Merge with Git
📖 Scenario: You are working on a team project using Git. Two team members have made changes to the same file in different branches. You need to merge these branches using a three-way merge to combine their changes safely.
🎯 Goal: Learn how to perform a three-way merge in Git to combine changes from two branches into one, resolving conflicts if they appear.
📋 What You'll Learn
Create a Git repository with an initial file
Create and switch to a new branch
Make changes in both branches
Perform a three-way merge to combine changes
💡 Why This Matters
🌍 Real World
Teams use three-way merges daily to combine code changes from multiple developers safely.
💼 Career
Understanding three-way merges is essential for software developers, DevOps engineers, and anyone collaborating on code using Git.
Progress0 / 4 steps
1
Initialize Git repository and create initial file
Run git init to create a new Git repository. Then create a file named project.txt with the content Hello World. Add and commit this file with the message Initial commit using git add project.txt and git commit -m "Initial commit".
Git
Need a hint?

Use git init to start the repo. Use echo to create the file. Then add and commit.

2
Create and switch to a new branch
Create a new branch called feature using git branch feature. Then switch to this branch using git checkout feature.
Git
Need a hint?

Use git branch feature to create and git checkout feature to switch branches.

3
Make changes in both branches
On the feature branch, change project.txt content to Hello from feature branch and commit with message Feature update. Then switch back to main branch using git checkout main, change project.txt content to Hello from main branch and commit with message Main update.
Git
Need a hint?

Use echo to overwrite the file content. Commit changes on each branch separately.

4
Perform a three-way merge
Merge the feature branch into main using git merge feature. If there are conflicts, resolve them by editing project.txt to contain Hello from both branches, then add and commit the merge with message Merge feature branch. Finally, print the content of project.txt using cat project.txt.
Git
Need a hint?

Use git merge feature. If conflict occurs, fix the file manually, then add and commit.