### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Create and Checkout a Git Branch Source: https://github.com/pcottle/learngitbranching/blob/main/generatedDocs/levels.html This is a shortcut command that creates a new branch and immediately switches to it. It's a convenient way to start new work on a separate branch. ```bash git checkout -b [yourbranchname] ``` -------------------------------- ### Push to Remote After Explicit Tracking Setup Source: https://github.com/pcottle/learngitbranching/blob/main/generatedDocs/levels.html This sequence sets 'foo' to track 'o/main' using 'git branch -u', makes a commit, and then pushes. The explicit tracking setup ensures the push operation targets the correct remote branch ('o/main'). ```bash git branch -u o/main foo; git commit; git push ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Checkout and Commit Example in Git Source: https://github.com/pcottle/learngitbranching/blob/main/generatedDocs/levels.html Demonstrates how HEAD changes its reference from a branch to a specific commit after a checkout and commit sequence. This illustrates the relationship between branches and commits in Git. ```git git checkout C1 git checkout main git commit git checkout C2 ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Create and Checkout New Branch Source: https://github.com/pcottle/learngitbranching/blob/main/generatedDocs/levels.html Creates a new branch named 'bugFix' and immediately switches the working directory to that new branch. ```git git checkout -b bugFix ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Create a New Git Branch Source: https://github.com/pcottle/learngitbranching/blob/main/generatedDocs/levels.html This command creates a new branch, which is essentially a lightweight pointer to a specific commit. Branches are used to diverge from the main line of development and isolate work. ```bash git branch newImage ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Checkout and Merge Another Branch Source: https://github.com/pcottle/learngitbranching/blob/main/generatedDocs/levels.html First, checks out the 'bugFix' branch, then merges the 'main' branch into it. If the target branch is an ancestor of the source branch, the branch pointer is simply moved forward. ```git git checkout bugFix git merge main ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Build and Run LearnGitBranching Locally (Bash) Source: https://github.com/pcottle/learngitbranching/blob/main/README.md This snippet details the steps to clone the LearnGitBranching repository, install dependencies, build the project for local testing, and push changes for contributions. It uses standard bash commands and the 'gulp.js' build tool. ```bash git clone cd learnGitBranching yarn install git checkout -b newAwesomeFeature vim ./src/js/git/index.js # some changes yarn gulp fastBuild # skips tests and linting, faster build # after building you can open up your browser to the index.html open ./index.html # file generated and see your changes vim ./src/js/git/index.js # more changes yarn gulp build # runs tests and lint git commit -am "My new sweet feature!" git push # go online and request a pull ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Define and Load Git Tutorial Levels in JavaScript Source: https://context7.com/pcottle/learngitbranching/llms.txt This snippet illustrates the structure for defining a Git tutorial level, including its name in multiple languages, goal state, solution, hints, and initial dialog. It then shows how to load and instantiate a Level object using this data, and how to listen for the 'levelSolved' event. ```javascript // Level definition structure exports.level = { "name": { "en_US": "Introduction to Git Commits", "es_ES": "Introducción a los commits de Git", "fr_FR": "Introduction aux commits avec Git" }, "goalTreeString": '{"branches":{"main":{"target":"C3"}},"commits":{"C0":{"parents":[]},"C1":{"parents":["C0"]},"C2":{"parents":["C1"]},"C3":{"parents":["C2"]}}}', "solutionCommand": "git commit;git commit", "startTree": '{"branches":{"main":{"target":"C1"}},"commits":{"C0":{"parents":[]},"C1":{"parents":["C0"]}}}', "hint": { "en_US": "Just type in 'git commit' twice to finish!", "es_ES": "¡Simplemente escribe 'git commit' dos veces para terminar!" }, "disabledMap": { "git revert": true }, "startDialog": { "en_US": { "childViews": [ { "type": "ModalAlert", "options": { "markdowns": ["## Git Commits", "A commit records a snapshot..."] } }, { "type": "GitDemonstrationView", "options": { "beforeMarkdowns": ["Let's see what this looks like..."], "afterMarkdowns": ["There we go! Awesome..."], "command": "git commit", "beforeCommand": "" } } ] } } }; // Load and start a level var Level = require('./level').Level; var levelData = require('./levels/intro/commits').level; var level = new Level({ level: levelData, deferred: Q.defer() }); // Check if level is solved level.on('levelSolved', function() { console.log('Level completed!'); }); ``` -------------------------------- ### Untitled No description -------------------------------- ### Initialize Sandbox in JavaScript Source: https://context7.com/pcottle/learngitbranching/llms.txt Initializes the sandbox environment for experimenting with Git commands. The sandbox automatically handles command submission, undo/redo, resetting, and remote repository cloning. Special commands like 'undo', 'reset', 'git clone', 'levels', 'build level', and 'import level' are available. ```javascript var Sandbox = require('./sandbox').Sandbox; // Initialize sandbox var sandbox = new Sandbox({ el: document.getElementById('mainVisSpace'), wait: false }); // Sandbox automatically handles: // - Command submission from UI // - Undo/redo functionality // - Reset to clean state // - Remote repository cloning // Special sandbox commands available: // - undo: revert last command // - reset: start with clean slate // - git clone: simulate remote repository // - levels: show available levels // - build level: create custom levels // - import level: load custom level from JSON ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Checkout Specific Parent Commit with Git Source: https://github.com/pcottle/learngitbranching/blob/main/generatedDocs/levels.html This command checks out the parent commit specified by the number. For merge commits, '^' followed by a number indicates which parent branch to follow. For example, 'main^2' checks out the second parent of the 'main' commit. ```bash git checkout main^ ``` ```bash git checkout main^2 ``` -------------------------------- ### Simulate Specific Remote Changes with Git FakeTeamwork Source: https://github.com/pcottle/learngitbranching/blob/main/generatedDocs/levels.html This demonstrates simulating a specific number of commits or changes to a particular branch on the remote repository using 'git fakeTeamwork'. For example, 'git fakeTeamwork foo 3' simulates three commits being pushed to the 'foo' branch. ```git git fakeTeamwork foo 3 ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Create Git Repository Visualization in JavaScript Source: https://context7.com/pcottle/learngitbranching/llms.txt This snippet shows how to create an interactive SVG visualization of a Git repository using the Visualization module. It initializes a Visualization instance within a specified DOM element and configures it with a tree string. It also demonstrates programmatic command execution and state export after the GitEngine is ready. ```javascript var Visualization = require('./visuals/visualization').Visualization; // Create a visualization in a container var vis = new Visualization({ el: document.getElementById('canvasHolder'), treeString: '{"branches":{"main":{"target":"C1"}},"commits":{"C0":{"parents":[]},"C1":{"parents":["C0"]}}}', noKeyboardInput: false, isGoalVis: false }); // The visualization automatically creates: // - Paper (Raphael canvas) // - GitEngine instance // - Commit, Branch, and Tag collections // - Event handling system // Access the git engine after initialization vis.customEvents.on('gitEngineReady', function() { var engine = vis.gitEngine; // Execute commands programmatically engine.commit(); engine.branch('newBranch'); engine.checkout('newBranch'); // Get current state var treeString = engine.exportTree(); console.log(treeString); }); ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description