lab 2 Create a Project

Goals

Create a “Hello, World” program 01

Starting in the empty working directory, create an empty directory named “hello”, then create a file named hello.c with the contents below.

Execute:

mkdir hello
cd hello

File: hello.c

#include <stdio.h>
int main()
{
  printf("Hello World!\n");
  return 0;
}

File: Makefile

CC = gcc
hello: hello.c

Create the Repository 02

You now have a directory with two files. To create a git repository from that directory, run the git init command.

Execute:

git init

Output:

$ git init
Initialized empty Git repository in /Users/jim/working/git/git_immersion/auto/hello/.git/

Specify Files To Be Ignored 03

You can tell git not to care at all about files you don't want in your repository (e.g., executable and object files, backup files, etc.). To do so, just create a file named ".gitignore" in your working directory.

File: .gitignore

hello
*.o
*~

In fact, it is a good idea to keep the ".gitgnore" file itself in the repository. We will therefore add it in the next section.

Add the program to the repository 04

Now let’s add the whole “Hello, World” program to the repository.

Execute:

git add hello.c
git add Makefile
git add .gitignore
git commit -m "First Commit"

You should see …

Output:

$ git add hello.c
$ git add Makefile
$ git add .gitignore
$ git commit -m "First Commit"
[master (root-commit) f8c335c] First Commit
 3 files changed, 12 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 Makefile
 create mode 100644 hello.c
$

Table of Contents