{"id":19356306,"url":"https://github.com/zectox/learngitbranching_codes","last_synced_at":"2026-02-16T15:04:16.026Z","repository":{"id":260256802,"uuid":"880779062","full_name":"ZecTox/learngitbranching_codes","owner":"ZecTox","description":"Answers to all the problems in the learngitbranching.js.org","archived":false,"fork":false,"pushed_at":"2024-11-09T21:48:20.000Z","size":160,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-13T06:26:22.846Z","etag":null,"topics":["git","github"],"latest_commit_sha":null,"homepage":"https://zectox.github.io/learngitbranching_codes/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZecTox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-30T10:45:23.000Z","updated_at":"2024-11-09T21:48:23.000Z","dependencies_parsed_at":"2025-01-06T17:46:29.875Z","dependency_job_id":"6a7e146e-5563-4ec5-81a4-e616e4e1bed4","html_url":"https://github.com/ZecTox/learngitbranching_codes","commit_stats":{"total_commits":14,"total_committers":2,"mean_commits":7.0,"dds":0.0714285714285714,"last_synced_commit":"1e566950aa89f2024108df47bc809f126ad41b07"},"previous_names":["zectox/learngitbranching_codes"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ZecTox/learngitbranching_codes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZecTox%2Flearngitbranching_codes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZecTox%2Flearngitbranching_codes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZecTox%2Flearngitbranching_codes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZecTox%2Flearngitbranching_codes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZecTox","download_url":"https://codeload.github.com/ZecTox/learngitbranching_codes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZecTox%2Flearngitbranching_codes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278555446,"owners_count":26006079,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","github"],"created_at":"2024-11-10T07:03:54.795Z","updated_at":"2025-10-06T03:33:46.438Z","avatar_url":"https://github.com/ZecTox.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# learngitbranching_codes\nMy answers to all the problems in the [learngitbranching.js.org](https://learngitbranching.js.org/)\n\u003e [!NOTE]\n\u003e I've used `git checkout` but you can use `git switch` instead of checkout.\n------------------------------------------------------------------------\n# GIT MAIN SECTION\n## Introduction Sequence\n### 1: Introduction to Git Commit\n```\ngit commit\ngit commit\n```\n\n### 2: Branching in Git\n```\ngit checkout -b bugFix\n```\n\n### 3: Merging in Git\n```\ngit checkout -b bugFix\ngit commit\ngit checkout main\ngit commit\ngit merge bugFix\n```\n\n### 4: Rebase Introduction\n```\ngit checkout -b bugFix\ngit commit\ngit checkout main\ngit commit\ngit checkout bugFix\ngit rebase main\n```\n\n## Ramping Up\n### 1: Detach yo' HEAD\n```\ngit checkout c4\n```\n\n### 2: Relative Refs (^)\n```\ngit checkout HEAD^\n```\n\n### 3: Relative Refs #2 (~)\n```\ngit checkout HEAD^\ngit branch -f main c6\ngit branch -f bugFix c0\n```\n\n### 4: Reversing Changes in Git\n```\ngit reset local^\ngit checkout pushed\ngit revert pushed\n```\n\n## Moving Work Around\n### 1: Cherry-pick Intro\n```\ngit cherry-pick c3 c4 c7\n```\n\n### 2: Interactive Rebase Intro\n```\ngit rebase -i HEAD~4\n```\n\n## A Mixed Bag\n### 1: Grabbing Just 1 Commit\n3 different answers that I find to solve the problem \n```\ngit branch -f bugFix c1\ngit cherry-pick c4\ngit branch -f main c4'\n```\nOR\n```\ngit rebase -i main\ngit branch -f main c4'\n```\nOR - ***BEST Solution***\n```\ngit rebase -i HEAD~3\ngit branch -f main c4'\n```\n\n### 2: Juggling Commits\n```\ngit rebase -i HEAD~2\ngit commit --amend\ngit rebase -i HEAD~2\ngit branch -f main c3''\n```\nOR\n```\ngit rebase -i HEAD~2\ngit rebase -i HEAD~1\ngit rebase -i HEAD~2\ngit branch -f main c3''\n```\n\n### 3: Juggling Commits #2\n```\ngit checkout main\ngit cherry-pick c2\ngit rebase -i HEAD~1\ngit cherry-pick c3\n```\nOR - ***BEST Solution***\n```\ngit checkout main\ngit cherry-pick c2\ngit branch -f main c1\ngit cherry-pick c2' c3\n```\n\n### 4: Git Tags\n```\ngit tag v0 c1\ngit tag v1 c2\ngit checkout c2 (OR) git checkout main^\n```\n\n### 5: Git Describe\n```\ngit describe main     #output: v0_2_gC2\ngit describe side     #output: v1_1_gC4\ngit describe bugFix   #output: v1_2_gC6\n```\n\n## Advanced Topics\n### 1: Rebasing over 9000 times\n```\ngit checkout bugFix\ngit rebase c2\ngit checkout main\ngit branch -f main c4\ngit rebase c3'\ngit branch -f main c5\ngit rebase c4'\ngit branch -f main c6\ngit rebase c5'\ngit branch -f main c7\ngit rebase c6'\ngit branch -f another c7'\ngit branch -f side c6'\n```\nOR\n```\ngit rebase main bugFix\ngit rebase bugFix side\ngit rebase side another\ngit branch -f main c7'\n```\nOR - ***BEST Soltion***\n```\ngit rebase main bugFix\ngit rebase bugFix side\ngit rebase side another\ngit rebase another main\n```\n\n### 2: Multiple parents\n```\ngit branch -f bugWork c2\n```\nOR - ***BEST Soltion***\n```\ngit branch bugWork main~^2~\n```\n\n### 3: Branch Spaghetti\n```\ngit rebase -i one main\ngit  branch -f main c5\ngit rebase -i one main\ngit branch -f main c5\ngit branch -f one c2'\ngit branch -f two c2''\ngit branch -f three c2\ngit checkout two\n```\nOR - ***BEST Solution***\n```\ngit checkout one\ngit cherry-pick c4 c3 c2\ngit checkout two\ngit cherry-pick c5 c4 c3 c2\ngit branch -f three c2\n```\n### Hope you are able to see this now\n\n\u003cimage src = \"images/git_main_completed.png\" width=500px\u003e\n\n------------------------------------------------------------------------------------\n\n# GIT REMOTE SECTION\n## Push \u0026 Pull -- Git Remotes!\n### 1: Clone Intro\n```\ngit clone\n```\n\n### 2: Remote Branches\n```\ngit commit\ngit checkout o/main\ngit commit\n```\n\n### 3: Git Fetchin'\n```\ngit fetch\n```\n\n### 4: Git Pullin'\n```\ngit fetch\ngit merge o/main\n```\nOR - ***BEST solution***\n```\ngit pull\n```\n\n### 5: Faking Teamwork\n```\ngit clone\ngit fakeTeamwork main 2\ngit commit\ngit pull\n```\nOR\n```\ngit clone\ngit commit\ngit fakeTeamwork main 2\ngit pull\n```\n\n### 6: Git Pushin'\n```\ngit commit\ngit commit\ngit push\n```\n\n### 7: Diverged History\n```\ngit clone\ngit fakeTeamwork main\ngit commit\ngit fetch\ngit rebase o/main\ngit push\n```\nOR - ***BEST Solution***\n```\ngit clone\ngit fakeTeamwork main\ngit commit\ngit pull --rebase\ngit push\n```\n\n### 8: Locked Main\n```\ngit checkout -b feature\ngit branch -f main c1\ngit push\n```\nOR - ***BEST Solution***\n```\ngit reset o/main\ngit checkout -b feature c2\ngit push      # Can also use- git push origin feature\n```\n\n## To Origin And Beyond -- Advanced Git Remotes!\n### 1: Push Main!\n```\ngit branch -f side3 c1\ngit pull origin main\ngit cherry-pick c2 c3 c4 c5 c6 c7\ngit branch -f side1 c2'\ngit branch -f side 2 c4'\ngit branch -f main c7'\ngit push origin main\n```\nOR - ***BEST Solution***\n```\ngit fetch     #Can also use- git fetch origin main\ngit rebase o/main side1\ngit rebase side1 side2\ngit rebase side2 side3\ngit rebase side3 main\ngit push      #Can also use- git push origin main\n```\n\n### 2: Merging with remotes\n```\ngit checkout main\ngit pull origin main\ngit merge side1\ngit merge side2\ngit merge side3\ngit push origin main\n```\n\n### 3: Remote Tracking\n```\ngit checkout -b side o/main\ngit commit\ngit pull --rebase\ngit push\n```\n\n### 4: Git push arguments\n```\ngit push origin main\ngit push origin foo\n```\n\n### 5: Git push arguments -- Expanded!\n```\ngit push origin main^:foo\ngit push origin foo:main\n```\n\n### 6: Fetch arguments\n```\ngit fetch origin c3:foo\ngit fetch origin c6:main\ngit checkout foo\ngit merge main\n```\n\n### 7: Source of nothing\n```\ngit push origin :foo\ngit fetch origin :bar\n```\n\n### 8: Pull arguments\n```\ngit fetch origin c3:foo\ngit fetch origin c2:side\ngit merge foo\ngit merge side\n```\nOR - ***BEST Solution***\n```\ngit pull origin c3:foo\ngit pull origin c2:side\n```\n\u003cp\u003e🧑‍💻 Huh, finally completed all levels.\u003c/p\u003e \n\u003cp\u003e\u003cimage src = \"images/git_alllevelscleared.png\" width=500px\u003e \u003cimage src = \"images/git_remote_completed.png\" width=500px\u003e\u003c/p\u003e\n\n\n\u003e [!NOTE]\n\u003e If found any mistake or better answers, send PR, I'll merge it. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzectox%2Flearngitbranching_codes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzectox%2Flearngitbranching_codes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzectox%2Flearngitbranching_codes/lists"}