?? Post 3 - Resolving Merge Conflicts Like a Pro

?? Post 3 - Resolving Merge Conflicts Like a Pro


? 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?

André Hiromi Arima

Software Engineer | Software Developer | Backend | .Net | C# | Docker | AWS

1 周

nice

回复
Alexandre Germano Souza de Andrade

Senior Software Engineer | Backend-Focused Fullstack Developer | .NET | C# | Angular | React.js | TypeScript | JavaScript | Azure | SQL Server

1 周

Useful tips, thanks for sharing ??

回复
André Luiz de Almeida Pereira

Full Stack Developer | .Net Engineer | C# | .Net Core | Angular | MS SQL Server

1 周

Nice content Thanks for sharing

回复
Gabriel Levindo

Android Developer | Mobile Software Engineer | Kotlin | Jetpack Compose | XML

1 周

Very informative!!

回复
Samuel Santos

Desenvolvedor Full stack | HTML, CSS, JavaScript, React | Node.js | Git & Github

1 周

Great post ????

回复

要查看或添加评论,请登录

Bruno Freitas的更多文章

社区洞察