pcottle / learnGitBranching

An interactive git visualization and tutorial. Aspiring students of git can use this app to educate and challenge themselves towards mastery of git!
https://pcottle.github.io/learnGitBranching/
MIT License
30.16k stars 5.72k forks source link

Incorrect implementation for git fetch/pull with colon ":" affecting remoteAdvance6 #1138

Closed juanmv94 closed 2 months ago

juanmv94 commented 2 months ago

In remoteAdvance6 level we execute the command git fetch origin foo~1:bar to move remote foo~ into local bar branch, but that's actually not allowed by Git, resulting in a fatal: Invalid refspec 'foo~1:bar' message.

When using colon ":", origins can be a remote branch name, or commit hash, no ~^ modifiers allowed. Also when using a remote branch as origin, example: git fetch origin foo:bar it will update bar but also updates o/foo not being reflected in the simulator.

These same issues affects git pull commands in the same way

pcottle commented 2 months ago

Good catch! Do you think just switching to commit hashes instead would solve the inconsistency but still provide a valuable lesson?

juanmv94 commented 2 months ago

Definitely that could be a workaround until it’s fixed on the simulator, although I think the most common way of using the colon fetch is with a branch name origin (updating o/branch)

pcottle commented 2 months ago

Alright @juanmv94 just updated the level -- let me know what you think: https://learngitbranching.js.org/?NODEMO&command=level%20remoteAdvanced6

juanmv94 commented 2 months ago

More issues discovered affecting fetch and pull commands: I'm making a pull request fixing all these issues including the previous ones

git fetch origin foo:bar (with HEAD on o/foo up to date, bar branch still doesn't exists) --> Already up to date!

Examples:

git clone git fetch origin main:foo

git fetch origin foo:bar (with current HEAD not part of history of foo) --> Your origin branch is out of sync with the remote branch and fetch cannot be performed

Examples:

git checkout -b foo c0 git commit git clone git fetch origin main:bar

git clone git fetch origin c0:foo