Master Git Hub Programming From Scratch

Clear, interactive, and structured coding lessons designed for absolute beginners.

Initializing Reositories

To initialize a repository, you turn a local directory on your computer into a tracked Git repository, which allows you to start saving versions of your code and eventually push it to GitHub.

Below we have given two scenarios to explain how to initialize a repository based on your project's current state:

Scenario 1: Starting a Brand New Project

Open your terminal (Mac/Linux) or Git Bash (Windows) and type the following commands. Make sure the email matches the one registered to your GitHub Account.

Use this if you are starting from absolute scratch with an empty folder.

  • Create and enter your project folder:

    mkdir my-new-project
    cd my-new-project
  • Initialize Git:

    git init

    This creates a hidden .git folder inside your directory to track changes)

  • Create your first file and save it:

    echo "# My Project" > README.md
    git add README.md
    git commit -m "First commit"

Scenario 2: Tracking an Existing Project Folder

Use this if you already have a folder full of code on your computer that you want to start tracking with Git.

  • Navigate to your existing folder:

    cd /path/to/your/existing-folder
  • Initialize Git:

    git init
  • Stage and commit all existing files:

    git add .
    git commit -m "Initial commit of existing project files"