Skip to content

lab 25 Navigating Branches

Goals

You now have two branches in your project:

Execute:

git hist --all

Output:

$ git hist --all
* 228a31e 2020-06-20 | Updated Rakefile (HEAD -> greet) [Jim Weirich]
* 98cfd8a 2020-06-20 | Hello uses Greeter [Jim Weirich]
* cf0438b 2020-06-20 | Added greeter class [Jim Weirich]
* 5aec14d 2020-06-20 | Added a Rakefile. (master) [Jim Weirich]
* 721b979 2020-06-20 | Moved hello.rb to lib [Jim Weirich]
* 907a445 2020-06-20 | Add an author/email comment [Jim Weirich]
* 4254c94 2020-06-20 | Added a comment (tag: v1) [Jim Weirich]
* c8b3af1 2020-06-20 | Added a default value (tag: v1-beta) [Jim Weirich]
* 30c2cd4 2020-06-20 | Using ARGV [Jim Weirich]
* 4445720 2020-06-20 | 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.