lab 9 Creating a Branch
Goals
- Learn how to create a local branch in a repository
It’s time to do a major rewrite of the hello world functionality. Since this might take awhile, you’ll want to put these changes into a separate branch to isolate them from changes in master.
Create a Branch 01
Let’s call our new branch ‘greet’.
Execute:
git checkout -b greet git status
NOTE: git checkout -b <branchname> is a shortcut for git branch <branchname> followed by a git checkout <branchname>.
Notice that the git status command reports that you are on the ‘greet’ branch.
Changes for Greet: Add a Greeter function. 02
File: greeter.h
void greet(const char * name);
File: greeter.c
#include "greeter.h"
#include <stdio.h>
void greet(const char * name)
{
printf("Hello %s!\n",name);
}
File: Makefile
CC = gcc hello: hello.c greeter.o greeter.o: greeter.c greeter.h
Execute:
git add greeter.h git add greeter.c git add Makefile git commit -m "Added greeter function"
Changes for Greet: Modify the main program 04
Update the hello.c file to use the greeter function
File: 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;
}
Execute:
git add hello.c git commit -m "Hello uses greet function"