Git - Create a Project

From EdWiki

GitLab - Create a Project

  • Goals
    Learn how to create a git repository from scratch.
  • Initializing a Repository in an existing Directory
    If you are starting to track an existing project in Git, you need to go to that project's directory and type
git init

This command creates a new subdirectory named .git that contains necessary repository files.
If you want to start version controlling existing files:

git add *.c
git add README
git commit -m "Initial project version"

At this point, you have a Git repository with tracked files and an initial commit.

In these DoItYourSelf excersizes, we will create files/diretories to start version controlling using git.

  • Create a “Hello, World” program
    Starting in the empty working directory, create an empty directory named “hello”, then create a file named hello.c with the contents below.
mkdir hello
cd hello
  • File : hello.c
#include <stdio.h>
#include <stdlib.h>
int main(void) {
    puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
    return EXIT_SUCCESS;
  • Create the Repository
    You now have a directory with a single file. To create a git repository from that directory, run the git init command.
git init
  • Add the program to the repository
    Now let’s add the “Hello, World” program to the repository.
git add hello.c
git commit -m "First Commit"