TheOdinProject / curriculum

The open curriculum for learning web development
https://www.theodinproject.com/
Other
9.99k stars 13.35k forks source link

Git Basics: Unrelated histories pitfall #27110

Closed damon314159 closed 9 months ago

damon314159 commented 9 months ago

Checks

Describe your suggestion

More than one learner has landed in the discord with a peculiar git issue. Steps to reproduce:

  1. Create a blank repo on GH - no initial commit is made since there are 0 files
  2. Clone and make an initial commit
  3. Create a README.md via the GH interface, which creates an "Add README.md" commit
  4. Attempt to push local to remote
  5. Refused since remote is further ahead
  6. Attempt to pull
  7. Refused since histories are unrelated.

What's happened is that you cloned a 0 commit repo, so you local initial commit started a tree. Then adding a readme directly on GH creates an entirely new tree since there are also 0 commits there. Then when you come to attempt the merge, they have unrelated histories. @c-auri and I have reverse engineered the steps above as the cause of problems learners have walked into.

Now the instructions on this lesson, if followed to the letter avoid this, by adding the readme when the repo is created, before the clone. However when they revisit creating a repo during recipes, they might not be reading as carefully, or something like that. Either way, a lesson note somewhere, be it here or in recipes, to avoid this situation seems to be warranted - especially since the fix is a bit beyond foundations

Path

Foundations

Lesson Url

https://www.theodinproject.com/lessons/foundations-git-basics

(Optional) Discord Name

Damon

(Optional) Additional Comments

No response

c-auri commented 9 months ago

Thanks for opening the issue!

I'd like to add that once this happens, it is easily solved by git pull --allow-unrelated-histories. But anybody new to git will not know that and I don't think it's a given that they will find somebody on the Discord that knows about it either. This can be a big source of frustration for new learners.

It's probably not possible to avoid it completely, since it already only happens if the student does not follow instructions 100%. But I think the priority goal should be to reduce the likelihood of it happening early on.

wise-king-sullyman commented 9 months ago

Thanks for submitting this! I agree that this is something we've seen a lot.

I would be on board with a note or rewording of what we currently have in the recipes project to be more assertive that people should more than likely go back and look at the instructions on setting a repo up again.

I think I would be against us even mentioning git pull --allow-unrelated-histories though. I don't think we should be enabling people to essentially disable some of the safety features built into git.