Skip to content
Kauxync

How to Create and Initialize a GitHub Repository: From Scratch to Remote

By Kaushalendra Kumar3 min read

GitGitHubWorkflowTutorial

Learn how to create a GitHub repository through both the web interface and the command line, wire up remotes, and set up your project structure.

A Git repository (or "repo") is the central tracking container for your project. It records every change, commit history, branch, and release tag inside a hidden .git folder at the project's root.

Here is how to create and initialize a repository using both the GitHub web interface and your local terminal.


Method 1: Create a Repository via GitHub UI (Top-Down)

This approach is best when starting a brand new project from scratch.

  1. Log into GitHub and click the + icon in the top-right corner, then select New repository (or visit github.com/new).
  2. Fill in the repository details:
    • Repository name: Use clear kebab-case (e.g., inventory-api or personal-portfolio).
    • Description: A short sentence explaining the project's purpose.
    • Visibility:
      • Public: Anyone on the internet can see your code. Ideal for open-source and portfolios.
      • Private: Only you and explicitly invited collaborators can view it.
    • Initialize with:
      • Check Add a README file (gives visitors immediate context).
      • Add .gitignore: Select your project's runtime (e.g., Node, Python, Go) to avoid checking in build output or node_modules.
      • Choose a license: MIT or Apache 2.0 for permissive open-source, or leave blank for proprietary work.
  3. Click Create repository.

Clone It to Your Machine

Copy the SSH clone URL from the green Code button, then open your terminal:

Snippet
# Clone the repository locally
git clone git@github.com:your-username/inventory-api.git

# Enter the project folder
cd inventory-api

# Inspect repository status
git status

Method 2: Connect an Existing Local Folder to GitHub (Bottom-Up)

If you already have code written locally on your computer and want to push it to a new GitHub repository:

Step 1: Initialize Git Locally

Navigate to your existing project folder in the terminal:

Snippet
cd /path/to/my-existing-project

# Initialize a new Git tracking database
git init -b main

Step 2: Add a .gitignore and README.md

Always create a .gitignore before making your first commit to prevent committing build artifacts, environment secrets, and heavy dependencies:

Snippet
# Example for a Node/TypeScript project
echo "node_modules/" >> .gitignore
echo ".env" >> .gitignore
echo "dist/" >> .gitignore
echo ".DS_Store" >> .gitignore

# Create a project overview
echo "# My Existing Project" > README.md

Step 3: Stage and Make the Initial Commit

Snippet
# Stage all files
git add .

# Create the first commit
git commit -m "chore: initial project commit"

Step 4: Create an Empty Repository on GitHub

Go to github.com/new:

  • Enter the matching repository name.
  • Do not check "Add a README", "Add .gitignore", or "Choose a license" (keeping the remote completely empty avoids merge conflicts on your first push).
  • Click Create repository.

Step 5: Link the Remote and Push

GitHub will show you the exact remote commands. Run them in your terminal:

Snippet
# Add the remote repository alias named 'origin'
git remote add origin git@github.com:your-username/my-existing-project.git

# Verify the remote URL
git remote -v

# Push your main branch and set upstream tracking (-u)
git push -u origin main

Quick Reference: Essential Repo Files

| File | Purpose | Why It Matters | | :--- | :--- | :--- | | README.md | Project landing page | Explains installation, usage, and project architecture to developers. | | .gitignore | Exclusions list | Stops build caches, keys, and dependencies from ever polluting version history. | | LICENSE | Legal rights | Defines how others can legally use, copy, or contribute to your project. |

With your repository created and linked to GitHub, the next step is mastering how to inspect, stage, and commit changes cleanly.

K

Author

Kaushalendra Kumar

Full-Stack Developer and Software Builder. Building software, exploring modern web architectures, and sharing technical breakdowns.

Thoughts or corrections? Let's talk: owner@kauxync.in

@kauxync on X →