lab 25 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 * 7a5c511 2013-10-06 | Updated Rakefile (HEAD, greet) [Ismail Dhorat] * 815cf27 2013-10-06 | Hello uses Greeter [Ismail Dhorat] * 209ff42 2013-10-06 | Added greeter class [Ismail Dhorat] * b3e19a3 2013-10-06 | Added a Rakefile. (master) [Ismail Dhorat] * 14f09c0 2013-10-06 | Moved hello.rb to lib [Ismail Dhorat] * 1fed2ec 2013-10-06 | Add an author/email comment [Ismail Dhorat] * dc44f2e 2013-10-06 | Added a comment (v1) [Ismail Dhorat] * 5ec54fd 2013-10-06 | Added a default value (v1-beta) [Ismail Dhorat] * e606a20 2013-10-06 | Using ARGV [Ismail Dhorat] * 5d95e74 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.