lab 25 Navigating Branches

Goals

You now have two branches in your project:

Execute:

git hist --all

Output:

$ git hist --all
* 6e84bb4 2013-10-06 | Updated Rakefile (HEAD, greet) [Ismail Dhorat]
* b90deb7 2013-10-06 | Hello uses Greeter [Ismail Dhorat]
* 0a6c49b 2013-10-06 | Added greeter class [Ismail Dhorat]
* 27b8b27 2013-10-06 | Added a Rakefile. (master) [Ismail Dhorat]
* 23944f0 2013-10-06 | Moved hello.rb to lib [Ismail Dhorat]
* 273edac 2013-10-06 | Add an author/email comment [Ismail Dhorat]
* 9efd33e 2013-10-06 | Added a comment (v1) [Ismail Dhorat]
* 8b9a1c6 2013-10-06 | Added a default value (v1-beta) [Ismail Dhorat]
* f6f4d6b 2013-10-06 | Using ARGV [Ismail Dhorat]
* f98d857 2013-10-06 | First Commit [Ismail Dhorat]

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: Ismail Dhorat (ismail@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