Skip to content

lab 22 Navigating Branches

Goals

You now have two branches in your project:

Execute:

git hist --all

Output:

$ git hist --all
* cc98109 2023-08-21 | Hello uses Greeter (HEAD -> greet) [Théophile Chevalier]
* d6aae18 2023-08-21 | Add greeter class [Théophile Chevalier]
* 9ab61ca 2023-08-21 | Moved hello.py to lib (main) [Théophile Chevalier]
* 7abea37 2023-08-21 | Add an author/email comment [Théophile Chevalier]
* 1c410c6 2023-08-21 | Add a comment (tag: v1) [Théophile Chevalier]
* 0bf384c 2023-08-21 | Display user input (tag: v1-beta) [Théophile Chevalier]
* 31c3945 2023-08-21 | Add some content [Théophile Chevalier]
* aa5d425 2023-08-21 | First Commit [Théophile Chevalier]

Switch to the Main Branch

Just use the git checkout command to switch between branches.

Execute:

git checkout main
cat lib/hello.py

Output:

$ git checkout main
Switched to branch 'main'
$ cat lib/hello.py
# Default is World
# Author: Jim ([email protected]) & Théophile ([email protected])
import sys

# Display user input
print(f"Hello, World! With user input : {sys.argv[0]}")

You are now on the main branch. You can tell because the hello.py file doesn’t use the Greeter class.

Switch Back to the Greet Branch.

Execute:

git checkout greet
cat lib/hello.py

Output:

$ git checkout greet
Switched to branch 'greet'
$ cat lib/hello.py
import sys

from greeter import Greeter

name = sys.argv[0]
greeter = Greeter(name)
greeter.greet()

The contents of the lib/hello.py confirms we are back on the greet branch.