git clone https://github.com/your-username/conflict-practice.git
cd conflict-practice
3. Create a new file, add some initial content, and push it to the remote repository. For example, create a file named example.txt:
echo "Initial content" > example.txt
git add example.txt
git commit -m "Add initial content"
git push origin main
git switch -c feature-branch
echo "Feature branch changes" > example.txt
git commit -am "Update example.txt on feature branch"
git push origin feature-branch
4. Go to GitHub, navigate to your conflict-practice repository, and create a new pull request from feature-branch to main
git switch main
echo "Main branch changes" > example.txt
git commit -am "Update example.txt on main branch"
git push origin main
-
On GitHub, you should see a message indicating that there is a conflict between the
feature-branchandmainbranches in the pull request. -
To resolve the conflict, click the Resolve conflicts button in the pull request.
-
In the web editor, you will see the conflicting changes marked with
<<<<<<<,=======, and>>>>>>>. Edit the file to resolve the conflicts by keeping the desired changes and removing the conflict markers. -
After resolving the conflicts, click the Mark as resolved button, and then click the Commit merge button to commit the changes.
-
Finally, click the Merge pull request button to merge the
feature-branchintomain.
Now you have successfully resolved a conflict using Git, GitHub, and pull requests. This process is common in real-world projects, so it's essential to understand and practice resolving conflicts.
- hello world