Skip
Arish's avatar

29. Creating a Remote Repository


Creating a Remote Repository

Let's create your first repository on GitHub.

Method 1: Create on GitHub Website

Step 1: Go to GitHub

  1. Log in to github.com
  2. Click the + icon in the top right
  3. Select New repository

Step 2: Fill Repository Details

  • Repository name: my-first-repo
  • Description: (optional) "My first Git repository"
  • Visibility: Public or Private
  • Initialize: You can optionally add:
    • README file
    • .gitignore template
    • License

Step 3: Create Repository

Click Create repository.

Step 4: Connect Local Repository

GitHub shows you commands to connect:

bash
1# For a new local repository
2echo "# my-first-repo" >> README.md
3git init
4git add README.md
5git commit -m "first commit"
6git branch -M main
7git remote add origin https://github.com/username/my-first-repo.git
8git push -u origin main
9
10# For existing local repository
11git remote add origin https://github.com/username/my-first-repo.git
12git branch -M main
13git push -u origin main

Method 2: Using GitHub CLI

Install GitHub CLI

bash
1# Mac
2brew install gh
3
4# Windows
5winget install --id GitHub.cli
6
7# Linux
8sudo apt install gh

Authenticate

bash
1gh auth login

Create Repository

bash
1# Create public repo
2gh repo create my-project --public
3
4# Create private repo
5gh repo create my-project --private
6
7# Create from current directory
8gh repo create --source=. --public

Complete Workflow: New Project

1. Create Local Project

bash
1mkdir my-project
2cd my-project
3git init
4echo "# My Project" > README.md
5git add README.md
6git commit -m "Initial commit"

2. Create Remote on GitHub

Go to github.com → New repository → Create

3. Connect and Push

bash
1git remote add origin https://github.com/username/my-project.git
2git push -u origin main

4. Verify

bash
1# Check remote is set
2git remote -v
3
4# Output:
5origin  https://github.com/username/my-project.git (fetch)
6origin  https://github.com/username/my-project.git (push)

Complete Workflow: Existing Project

1. Navigate to Project

bash
1cd existing-project

2. Initialize Git (if needed)

bash
1git init
2git add .
3git commit -m "Initial commit"

3. Create Remote and Connect

bash
1# Create on GitHub first, then:
2git remote add origin https://github.com/username/existing-project.git
3git push -u origin main

Repository Settings

Visibility

  • Public: Anyone can see (free)
  • Private: Only you and collaborators (free for personal)

Branch Protection

In Settings → Branches:

  • Require pull request reviews
  • Require status checks
  • Restrict who can push

Collaborators

In Settings → Collaborators:

  • Add team members by username or email

SSH vs HTTPS

Using HTTPS

bash
1git remote add origin https://github.com/username/repo.git
2# Will prompt for credentials

Using SSH

bash
1git remote add origin git@github.com:username/repo.git
2# Uses SSH key (no password prompts)

Switch from HTTPS to SSH

bash
1git remote set-url origin git@github.com:username/repo.git

Summary

Creating a remote repository:

  1. Create on GitHub (website or CLI)
  2. Initialize locally (if needed)
  3. Add remote: git remote add origin URL
  4. Push: git push -u origin main

Practice this in the project task!