![panel 1: when pushing/pulling, the hardest problems are caused by diverged branches sad error messages: - ! [rejected] main -> main (non fast-forward) - fatal: Not possible to fast-forward, aborting - fatal: Need to specify how to reconcile divergent branches. panel 2: what are diverged branches it looks like this (picture) panel 3: there are 4 possibilities with a remote branch 1. up to date 2. need to pull 3. need to push 4. diverged (need to decide how to solve it) (some pictures too) panel 4: how to tell your branches have diverged: git status 1. git fetch (get the latest remote state first) 2. git status Your branch and 'origin/main' have diverged, and have 1 and 1 different commits each, respectively. (diverged is highlighted) panel 5: fix diverged branches before making more commits (pictures of okay state and bad state) panel 6: there's no one solution person: "on the next page we'll talk about some options!"](https://pbs.twimg.com/media/GHWxMreXkAA1oxl.jpg?name=small&format=webp)
ALT panel 1: when pushing/pulling, the hardest problems are caused by diverged branches sad error messages: - ! [rejected] main -> main (non fast-forward) - fatal: Not possible to fast-forward, aborting - fatal: Need to specify how to reconcile divergent branches. panel 2: what are diverged branches it looks like this (picture) panel 3: there are 4 possibilities with a remote branch 1. up to date 2. need to pull 3. need to push 4. diverged (need to decide how to solve it) (some pictures too) panel 4: how to tell your branches have diverged: git status 1. git fetch (get the latest remote state first) 2. git status Your branch and 'origin/main' have diverged, and have 1 and 1 different commits each, respectively. (diverged is highlighted) panel 5: fix diverged branches before making more commits (pictures of okay state and bad state) panel 6: there's no one solution person: "on the next page we'll talk about some options!"

ALT panel 1: there are 3 options for combining branches * merge * rebase * squash for example, let's say we're combining these 2 branches: (hard to describe diagram panel 2: diagram with the results of git rebase / git merge / git merge --squash panel 3: all 3 methods result in the EXACT SAME FILES some differences are: * the diff git shows you for the final commit * the specific flavour of suffering the method causes panel 4: merge pro: if you mess something up, the original commits are still in your branch's history pain: when I look at histories like this I feel dread (picture of a git history with a lot of merges) panel 5: rebase pro: you can keep your git history simple: (diagram for a git history that's a line) pain: harder to learn, harder to undo, easier to mess up (I love rebase though!) panel 6: rebase pro: have 20 messy commits? nobody needs to know! And it's pretty simple to use. pain: "ugh, someone squashed their 3000-line branch into 1 commit"

ALT panel 1: you might expect git to enforce some rules about branches some rules you might imagine: * you can't remove commits from a branch, only add them * the `main` branch has to stay more less in sync with `origin/main` But there are no rules. git character with demon hat: "want to do something horrible to your branch? no problem! " panel 2: there are literally no rules commands that you can use to do weird stuff to a branch: * git reset * git rebase panel 3: instead of rules, we have conventions for example: * run `git pull` often to keep your `main` up to date * if you're working with a big team, don't commit to `main` directly git demon: "you've just gotta be really careful to not do the wrong thing and not mess up your branch" person with curly hair: "um... thanks?" panel 4: our only saviour: the reflog git reflog BRANCHNAME will show you the history of every change to the branch, so you can always undo the reflog is a VERY unfriendly UI, but it's always there.
























