25. Navigating Branches

Goals

  • To learn how to navigate between the repository branches

Now your project has two branches:

Run:

git hist --all

Result:

$ git hist --all
* 07a2a46 2011-03-09 | Updated index.html (HEAD, style) [Marina Pushkova]
* 649d26c 2011-03-09 | Hello uses style.css [Marina Pushkova]
* 1f3cbd2 2011-03-09 | Added css stylesheet [Marina Pushkova]
* 8029c07 2011-03-09 | Added index.html. (master) [Marina Pushkova]
* 567948a 2011-03-09 | Moved hello.html to lib [Marina Pushkova]
* 6a78635 2011-03-09 | Add an author/email comment [Marina Pushkova]
* fa3c141 2011-03-09 | Added HTML header (v1) [Marina Pushkova]
* 8c32287 2011-03-09 | Added standard HTML page tags (v1-beta) [Marina Pushkova]
* 43628f7 2011-03-09 | Added h1 tag [Marina Pushkova]
* 911e8c9 2011-03-09 | First Commit [Marina Pushkova]

01 Switching to the Master branch

To switch between branches simply use the git checkout command.

Run:

git checkout master
cat lib/hello.html

Result:

$ git checkout master
Switched to branch 'master'
$ cat lib/hello.html
<!-- Author: Marina Pushkova (marina@githowto.com) -->
<html>
  <head>
  </head>
  <body>
    <h1>Hello, World!</h1>
  </body>
</html>

Now we are on the Master branch. It can be proven by the hello.html file that does not use styles from style.css.

02 Let us return to the style branch.

Run:

git checkout style
cat lib/hello.html

Result:

$ git checkout style
Switched to branch 'style'
$ cat lib/hello.html
<!-- Author: Marina Pushkova (marina@githowto.com) -->
<html>
  <head>
    <link type="text/css" rel="stylesheet" media="all" href="style.css" />
  </head>
  <body>
    <h1>Hello, World!</h1>
  </body>
</html>

We are back to a style branch that can be proven by the contents of lib/hello.html.

SVN?
© 2011-2014 Git How To. All rights reserved / Contact us