Skip to main content
•3 min read

What Even Is a Merge Conflict

techgitlearning

today i experienced my first merge conflict and honestly? i thought i broke the entire internet.

we're doing a group project in one of my classes (more on that nightmare later) and we decided to use github like "real developers". this was a mistake.

how it started

me: makes changes to file me: tries to push git: "error: failed to push some refs" me: sweating

how it's going

after an hour of googling, stack overflow tabs, and one near-mental breakdown, i finally understand what happened.

basically: i edited a file. my teammate edited the same file. we both tried to push. git said "absolutely not" and made us fight it out.

the dreaded merge conflict

when you open a file with a merge conflict, it looks like this:

<<<<<<< HEAD
my beautiful code that i wrote
=======
my teammate's different code
>>>>>>> their-branch

the first time i saw this i genuinely thought my file was corrupted. i almost deleted everything and started over.

(pro tip: don't do that.)

what i learned

  1. git pull before you git push
  2. communicate with your team about who's editing what
  3. the <<<<<<< markers are git's way of showing you both versions
  4. you're supposed to manually decide which code to keep
  5. you can have both! or neither! you're the boss!

the commands that saved me

git fetch origin
git merge origin/main
# manually fix the conflicts in the file
git add .
git commit -m "resolved merge conflict"
git push

i've run this sequence so many times now it's muscle memory.

git is actually amazing

hot take but hear me out: once you understand what git is doing, it's kind of incredible.

it's keeping track of every change you've ever made. it lets multiple people work on the same project without destroying each other's work. it has a time machine built in (git checkout to any previous commit).

the learning curve is just... steep. very steep. vertical, some might say.

resources that helped

  • "oh shit, git" (best website name ever)
  • the git documentation (surprisingly readable)
  • youtube videos explaining git like i'm five
  • my friend who's a second-year and very patient

current status

i now understand: commit, push, pull, branch, merge, checkout, and stash.

i still don't understand: rebase, cherry-pick, or why my git history looks like abstract art.


baby steps. at least my code is backed up now.