lab 25 Navigating Branches

Goals

You now have two branches in your project:

Execute:

git hist --all

Output:

$ git hist --all
* 28917a4 2013-04-13 | Updated Rakefile (HEAD, greet) [Jim Weirich]
* 4dac415 2013-04-13 | Hello uses Greeter [Jim Weirich]
* 39347b3 2013-04-13 | Added greeter class [Jim Weirich]
* 96ee164 2013-04-13 | Added a Rakefile. (master) [Jim Weirich]
* 0f36766 2013-04-13 | Moved hello.rb to lib [Jim Weirich]
* eb30103 2013-04-13 | Add an author/email comment [Jim Weirich]
* 1f7ec5e 2013-04-13 | Added a comment (v1) [Jim Weirich]
* 582495a 2013-04-13 | Added a default value (v1-beta) [Jim Weirich]
* 323e28d 2013-04-13 | Using ARGV [Jim Weirich]
* 9416416 2013-04-13 | First Commit [Jim Weirich]

Switch to the Master Branch 01

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. 02

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.

Table of Contents