To resolve merge conflicts in Git, follow these steps:
Steps to Resolve Merge Conflicts:
1.Pull the Latest Changes: Update your local branch with the latest changes from the remote repository:
git pull
2.Check for Conflicts: Run the following to identify files with conflicts:
git status
3.Open the Conflicted File: Use a text editor to review the conflict:
vim index.html
4.Resolve the Conflict: Look for conflict markers like <<<<<<< HEAD, =======, and >>>>>>>. These markers indicate changes from your branch and the one being merged. Here's an example conflict:
<<<<<<< HEAD
<p>Welcome to the homepage!</p>
<p>Explore our latest features!</p>
>>>>>>> feature-branch
5.Edit and Remove Markers: Choose which version to keep, or combine the changes as needed. For example:
Keeping your branch:
<p>Welcome to the homepage!</p>
Keeping the feature branch:
<p>Explore our latest features!</p>
Combining both:
<p>Welcome to the homepage! Explore our latest features!</p>
6.Stage the File: Once resolved, stage the changes:
git add index.html
7.Commit the Changes: Commit the resolved changes with a meaningful message:
git commit -m "Resolved merge conflict in index.html"
8.Push the Changes: Push the resolved changes to the remote branch:
git push