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) [Alexander Shvets] * 649d26c 2011-03-09 | Hello uses style.css [Alexander Shvets] * 1f3cbd2 2011-03-09 | Added css stylesheet [Alexander Shvets] * 8029c07 2011-03-09 | Added index.html. (master) [Alexander Shvets] * 567948a 2011-03-09 | Moved hello.html to lib [Alexander Shvets] * 6a78635 2011-03-09 | Add an author/email comment [Alexander Shvets] * fa3c141 2011-03-09 | Added HTML header (v1) [Alexander Shvets] * 8c32287 2011-03-09 | Added standard HTML page tags (v1-beta) [Alexander Shvets] * 43628f7 2011-03-09 | Added h1 tag [Alexander Shvets] * 911e8c9 2011-03-09 | First Commit [Alexander Shvets]
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: Alexander Shvets (alex@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 fact the hello.html
file 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: Alexander Shvets (alex@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 the style branch which can be proven by the fact the hello.html
file uses styles from style.css
.