lab 2 Create a Project
Goals
- Learn how to create a git repository from scratch.
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
- Home Cover Page
- Session: Getting Started
- 1: Setup
- Session: Basics
- 2: Create a Project
- 3: Checking Status
- 4: Making Changes
- 5: Staging Changes
- 6: Committing Changes
- Session: Dealing with the Past
- 7: History & aliases
- 8: Getting Old Versions
- Session: Branching
- 9: Creating a Branch
- 10: Navigating Branches
- 11: Changes in Master
- 12: Viewing Diverging Branches
- Session: Merging and Conflicts
- 13: Merging
- 14: Creating a Conflict
- 15: Resolving Conflicts
- Session: Multiple Repositories
- 16: Multiple Repositories
- 17: Cloning Repositories
- 18: Review the Cloned Repository
- 19: What is Origin?
- 20: Remote Branches
- 21: Change the Original Repository
- 22: Pushing a change
- 23: Fetching Changes
- 24: Merging Fetched Changes
- Session: Distributed workflow
- 25: Setup the repositories
- 26: Configure remotes
- 27: Developer contribution and pull request
- 28: Integration