?? Post 3 - Resolving Merge Conflicts Like a Pro
Bruno Freitas
Senior React Developer | Full Stack Developer | JavaScript | TypeScript | Node.js
? Merge conflicts happen when Git can't automatically merge changes. Don't panic—resolving them is easy!
?? Why do conflicts happen?
Conflicts usually occur when:
? Two people change the same file in different ways
? A branch modifies a file that has changed in main
?? Simulating a Merge Conflict
Try this:
1?? Create a branch and modify a file:
git branch conflict-demo
git switch conflict-demo
echo "This is a change in conflict-demo" > conflict.txt
git add conflict.txt && git commit -m "Change in conflict-demo"
2?? Switch back to main and modify the same file:
git switch main
echo "This is a change in main" > conflict.txt
git add conflict.txt && git commit -m "Change in main"
3?? Now, try merging conflict-demo:
git merge conflict-demo
You’ll see something like:
CONFLICT (content): Merge conflict in conflict.txt
?? Resolving the Conflict
1?? Open the file and choose which version to keep.
2?? After fixing, mark the conflict as resolved:
git add conflict.txt
git commit -m "Resolve conflict in conflict.txt"
?? Next post: How to write better commit messages and improve your Git history!
?? What’s the worst merge conflict you’ve faced?
Software Engineer | Software Developer | Backend | .Net | C# | Docker | AWS
1 周nice
Senior Software Engineer | Backend-Focused Fullstack Developer | .NET | C# | Angular | React.js | TypeScript | JavaScript | Azure | SQL Server
1 周Useful tips, thanks for sharing ??
Full Stack Developer | .Net Engineer | C# | .Net Core | Angular | MS SQL Server
1 周Nice content Thanks for sharing
Android Developer | Mobile Software Engineer | Kotlin | Jetpack Compose | XML
1 周Very informative!!
Desenvolvedor Full stack | HTML, CSS, JavaScript, React | Node.js | Git & Github
1 周Great post ????