Skip to content

lab 25 Navigating Branches

Goals

You now have two branches in your project:

Execute:

git hist --all

Output:

$ git hist --all
* 4721c3f 2020-05-30 | Updated Rakefile (HEAD -> greet) [Jim Weirich]
* 4689e1b 2020-05-30 | Hello uses Greeter [Jim Weirich]
* e685fb0 2020-05-30 | Added greeter class [Jim Weirich]
* 128a484 2020-05-30 | Added a Rakefile. (master) [Jim Weirich]
* a3cf03d 2020-05-30 | Moved hello.rb to lib [Jim Weirich]
* 96c1fec 2020-05-30 | Add an author/email comment [Jim Weirich]
* 9811d9e 2020-05-30 | Added a comment (tag: v1) [Jim Weirich]
* 3344f03 2020-05-30 | Added a default value (tag: v1-beta) [Jim Weirich]
* 3cb4c15 2020-05-30 | Using ARGV [Jim Weirich]
* dfb5614 2020-05-30 | First Commit [Jim Weirich]

Switch to the Master Branch

Just use the git checkout command to switch between branches.

Execute:

git checkout master
cat lib/hello.rb

Output:

$ git checkout master
Switched to branch 'master'
$ cat lib/hello.rb
# Default is World
# Author: Jim Weirich (jim@somewhere.com)
name = ARGV.first || "World"

puts "Hello, #{name}!"

You are now on the master branch. You can tell because the hello.rb file doesn’t use the Greeter class.

Switch Back to the Greet Branch.

Execute:

git checkout greet
cat lib/hello.rb

Output:

$ git checkout greet
Switched to branch 'greet'
$ cat lib/hello.rb
require 'greeter'

# Default is World
name = ARGV.first || "World"

greeter = Greeter.new(name)
puts greeter.greet

The contents of the lib/hello.rb confirms we are back on the greet branch.