Created
October 18, 2025 06:35
-
-
Save frroossst/ae07c8e7f3451a861b6beb0857a21fef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| mkdir git-conflict-demo | |
| cd git-conflict-demo || exit | |
| git init | |
| # Detect default branch name (master or main) | |
| DEFAULT_BRANCH=$(git symbolic-ref --short HEAD) | |
| # Initial file | |
| echo "Line 1" > file.txt | |
| echo "Line 2" >> file.txt | |
| echo "Line 3" >> file.txt | |
| git add file.txt | |
| git commit -m "Initial commit" | |
| # Create branch foo and modify line 2 | |
| git checkout -b foo | |
| sed -i 's/Line 2/Foo branch changes line 2/' file.txt | |
| git commit -am "Foo modifies line 2" | |
| # Go back to default branch and create bar | |
| git checkout "$DEFAULT_BRANCH" | |
| git checkout -b bar | |
| sed -i 's/Line 2/Bar branch changes line 2/' file.txt | |
| git commit -am "Bar modifies line 2" | |
| # Make a conflicting change on default branch after foo and bar | |
| git checkout "$DEFAULT_BRANCH" | |
| sed -i 's/Line 3/Default branch changes line 3/' file.txt | |
| git commit -am "Default branch modifies line 3" | |
| echo "Repository setup complete!" | |
| echo "Branches 'foo', 'bar', and '$DEFAULT_BRANCH' all have changes that will conflict." | |
| echo "Try merging or rebasing to see multiple conflicts." | |
| echo "DO:" | |
| echo " git checkout foo" | |
| echo "TRY:" | |
| echo " git merge bar" | |
| echo " git merge $DEFAULT_BRANCH" | |
| echo "or" | |
| echo " git rebase bar" | |
| echo " git rebase $DEFAULT_BRANCH" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment