Phase 0: Pre-flight Check (Crucial)​

Before starting, ensure you aren't about to push your whole computer by accident.

  1. Open Terminal.

  2. Run: git rev-parse --show-toplevel

  3. If it says /home/yourname or any folder above your project:

    • Run cd /path/to/that/wrong/folder

    • Run rm -rf .git to stop tracking everything.

  4. If it says fatal: not a git repository: You are safe. Proceed


Phase 1: Setup & Login (One-Time Setup)

1. Install & Configure Git

Bash
sudo apt update && sudo apt install git -y
git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"​​

2. Generate SSH Key

Bash

ssh-keygen -t ed25519 -C "your_email@example.com"
# Press Enter for all prompts (no passphrase needed for simple setup)​​

3. Activate Key Agent

Bash

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

4. Upload Key to GitHub

  1. Print your key: cat ~/.ssh/id_ed25519.pub

  2. Copy the output (starts with ssh-ed25519...).

  3. Go to GitHub.comSettings (top right avatar) → SSH and GPG keys.

  4. Click New SSH key, paste the code, and click Add SSH key.

5. Test Connection

Bash

ssh -T git@github.com
# Type "yes" if asked. Success message: "Hi [User]! You've successfully authenticated..."​​


Phase 2: Create Remote Repository

  1. Go to GitHub.com and click the + (top right) → New repository.

  2. Repo Name: Name it (e.g., my-project).

  3. Privacy: Public or Private.

  4. IMPORTANT: Do NOT check "Add a README", .gitignore, or license. Keep it empty.

    Reason: You already have project files on your computer. If you create new files (like a README) on GitHub now, the two histories will conflict, and your push will be rejected.

  5. Click Create repository.

  6. Copy the SSH URL shown (e.g., git@github.com:username/my-project.git).



Phase 3: Connect & Push Local Code

Go to your actual project folder on your computer:

Bash

# 1. Enter your project folder
cd ~/path/to/your/project

# 2. Initialize Git (only if you haven't yet)
git init

# 3. Add files and commit
git add .
git commit -m "First commit"

# 4. Rename branch to 'main' (standard practice)
git branch -M main

# 5. Link to the GitHub repo you just created
# (Replace the URL below with the one you copied in Phase 2)
git remote add origin git@github.com:YourUsername/YourRepoName.git

# 6. Push code
git push -u origin main
← Back to Learning Journey