lab 10 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:
* 947edf2 2015-09-29 | Hello uses greet function (HEAD -> greet) [Jim Weirich] * 9f9f376 2015-09-29 | Added greeter function [Jim Weirich] * e801e10 2015-09-29 | Using argv [Jim Weirich] * 21c17bd 2015-09-29 | First commit [Jim Weirich]
Switch to the Master Branch 01
Just use the git checkout command to switch between branches.
Execute:
git checkout master cat hello.c
Output:
$ git checkout master
Switched to branch 'master'
$ cat hello.c
#include <stdio.h>
int main(int argc, char *argv[])
{
if (argc > 1) {
printf("Hello %s!\n",argv[1]);
} else {
printf("Hello World!\n");
}
return 0;
}
You are now on the master branch. You can tell because the hello.c file doesn’t use the greet function.
Switch Back to the greet Branch. 02
Execute:
git checkout greet cat hello.c
Output:
$ git checkout greet
Switched to branch 'greet'
$ cat hello.c
#include <stdio.h>
#include "greeter.h"
int main(int argc, char *argv[])
{
if (argc > 1) {
greet(argv[1]);
} else {
greet("World");
}
return 0;
}
The contents of the hello.c confirms we are back on the greet branch.