Outreachy: Day25

A snapshot of my conversation with Julien (tl;dr: git troubles)

(Julien is super nice and he puts lots of smileys and reassuring phrases in between, but I skipped those here for dramatic purposes)

Me: I think I’ve broken my fork and local master – do you think it’s okay if I delete the fork and start all over?

Julien: it’s not a problem to delete everything and start over, but usually there’s a better way — and you’ll learn better if you try to fix the problem

(Julien likes using problems for pedagogical purposes…)

Me: Yes, I’ve been trying to fix it for the last number of days, but I think I put too many ‘-f’ in the mix and now it won’t start

(It’s not a good idea, but when I’m tired of reading errors, I like to force git to do stuff. Also writing -f in the terminal makes me feel so powerful…)

Me: If you look at my latest PR it’s also strange: I only changed 3 files, but it added other files to the commit as well

Me: Right now, I squashed it ok, but it said 19 files were changed – even though I changed fewer than that

Me: I tried with Git Kraken too, thought visualising might help, no luck there either

Julien: usually you don’t need to delete everything and start over, you can just start a new branch off master

Julien: remember branches and tags are just “pointers” to specific commits (hashes)

Julien: you can move them at your will

Me: I did the soft reset already

Me: My master was being a bit wonky – it kept merging changes that were only PR

Julien: you can start a branch off the remote master

Julien: you can reset your master too

Me: oh

(lightbulb moment No. 1)

Julien: git checkout -b branch remote/master

Julien: (replace remote with upstream in your case, I think)

Julien: git reset --hard upstream/master

Julien: (of course after a git fetch upstream)

Julien: reset moves the “pointer” of the branch to a different commit hash

Me: oh

(lightbulb moment No. 2)

Julien: with --hard it changes your local checked out files too

Julien: so it’s a bit dangerous, make sure you really want to lose the local changes


Julien: if you’re afraid of losing something, just create a new branch off of your current branch, and work on this branch; the other branch won’t change at all

Me: Sigh.

(But it’s fixed now!)