Phase 0: Pre-flight Check (Crucial)
Before starting, ensure you aren't about to push your whole computer by accident.
Open Terminal.
Run:
git rev-parse --show-toplevelIf it says
/home/yournameor any folder above your project:Run
cd /path/to/that/wrong/folderRun
rm -rf .gitto stop tracking everything.
If it says
fatal: not a git repository: You are safe. Proceed
Phase 1: Setup & Login (One-Time Setup)
1. Install & Configure Git
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
Print your key:
cat ~/.ssh/id_ed25519.pubCopy the output (starts with
ssh-ed25519...).Go to GitHub.com → Settings (top right avatar) → SSH and GPG keys.
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
Go to GitHub.com and click the + (top right) → New repository.
Repo Name: Name it (e.g.,
my-project).Privacy: Public or Private.
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.
Click Create repository.
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