lab 23 Navigating Branches
Goals
- Learn how to navigate between the branches of a repository
You now have two branches in your project:
Execute:
git hist --all
Output:
$ git hist --all * f52644d 2019-06-27 | Updated package (HEAD -> greet) [Halle Bot] * 455c54f 2019-06-27 | Hello uses Greeter [Halle Bot] * 4fb8bde 2019-06-27 | Added greeter class [Halle Bot] * 2b04803 2019-06-27 | Added a package.json. (main) [Halle Bot] * b65b430 2019-06-27 | Moved hello.js to lib [Halle Bot] * 4535421 2019-06-27 | Add an author/email comment [Halle Bot] * 59992ce 2019-06-27 | Added a comment (tag: v1) [Halle Bot] * 20a6c79 2019-06-27 | Added a default value (tag: v1-beta) [Halle Bot] * 6915d41 2019-06-27 | Using process.argv [Halle Bot] * 284070d 2019-06-27 | First Commit [Halle Bot]
Switch to the Main Branch
Just use the git checkout
command to switch between branches.
Execute:
git checkout main cat lib/hello.js
Output:
$ git checkout main Switched to branch 'main' $ cat lib/hello.js // Default is World // Author: Jim Weirich (jim@somewhere.com) const name = process.argv[2] || "World" console.log(`Hello, ${name}!`);
You are now on the main branch. You can tell because the hello.js file doesn’t use the Greeter
class.
Switch Back to the Greet Branch.
Execute:
git checkout greet cat lib/hello.js
Output:
$ git checkout greet Switched to branch 'greet' $ cat lib/hello.js const { Greeter } = require('./greeter'); // Default is World const name = process.argv[2] || "World" const greeter = new Greeter(name); console.log(greeter.greet());
The contents of the lib/hello.js
confirms we are back on the greet branch.