Skip to content

Latest commit

 

History

History
476 lines (355 loc) · 11.2 KB

File metadata and controls

476 lines (355 loc) · 11.2 KB

Git & GitHub Complete Beginner's Guide

🎯 What You'll Learn

This guide explains how to connect your local code to GitHub repositories, using simple terms and practical examples. Perfect for beginners who are new to version control!


🤔 What Are Git and GitHub?

Git (The Tool)

Think of Git as a smart diary for your code:

  • 📝 Tracks every change you make to your files
  • 🕰️ Remembers history - you can see what changed and when
  • 🔄 Allows you to go back to any previous version
  • 👥 Helps teams work together without overwriting each other's work

GitHub (The Website)

Think of GitHub as a library in the cloud:

  • 📚 Stores your code online safely
  • 🌐 Makes it accessible anywhere with internet
  • 👥 Lets others see and contribute to your projects
  • 🔄 Syncs with your local Git diary

Simple Analogy:

  • Your computer = Your personal workspace
  • Git = Your personal diary of changes
  • GitHub = Public library where you store copies of your diary

🗣️ Essential Terms (Beginner-Friendly)

Term Simple Explanation Real Example
Repository (Repo) A project folder with Git tracking Your "ParkerHub" folder
Commit Saving a snapshot of your changes "Added login feature"
Push Uploading your changes to GitHub Sending your diary to the library
Pull Downloading changes from GitHub Getting updates from the library
Branch A separate version to work on "main" (stable) vs "testing" (experimental)
Clone Making a copy of a GitHub repo locally Downloading someone's project
Fork Making your own copy of someone's repo Taking a book to write your own version

🚀 Two Common Scenarios

Scenario A: You Have Local Code (Your Situation)

You wrote code on your computer and want to put it on GitHub.

Scenario B: Starting from GitHub

You want to work on an existing GitHub project.


📋 One-Time Setup (Do This Once)

1. Install Git

# Check if Git is installed
git --version

# If not installed, download from: https://git-scm.com/

2. Configure Git with Your Identity

# Set your name (use your real name)
git config --global user.name "Your Full Name"

# Set your email (use your GitHub email)
git config --global user.email "your.email@example.com"

# Verify your settings
git config --list | grep user

3. Set Up GitHub Authentication

Option A: Personal Access Token (Recommended)

  1. Go to GitHub.com → Settings → Developer settings → Personal access tokens
  2. Generate new token with "repo" permissions
  3. Copy the token (save it somewhere safe!)

Option B: SSH Key (Advanced)

# Generate SSH key
ssh-keygen -t rsa -b 4096 -C "your.email@example.com"

# Add to GitHub: Settings → SSH and GPG keys → New SSH key

🏗️ Scenario A: Connect Local Code to GitHub

Step 1: Create GitHub Repository

  1. Go to GitHub.com
  2. Click green "New" button
  3. Enter repository name (e.g., "MyProject")
  4. Choose Public or Private
  5. DON'T check "Add a README file" (since you have local code)
  6. Click Create repository

Step 2: Initialize Git in Your Local Project

# Navigate to your project folder
cd "C:\path\to\your\project"

# Initialize Git (creates .git folder)
git init

# Check status
git status

Step 3: Create .gitignore File

# Create .gitignore file to exclude unnecessary files
# For Python projects:

Create .gitignore file with this content:

# Python
__pycache__/
*.py[cod]
*.so
*.egg-info/
dist/
build/

# Virtual Environment
venv/
env/
ENV/

# IDE
.vscode/
.idea/
*.swp

# OS
.DS_Store
Thumbs.db

# Database
*.sqlite3
*.db

# Logs
*.log

# Environment variables
.env

Step 4: Add and Commit Your Code

# Add all files to staging area
git add .

# Check what will be committed
git status

# Create your first commit
git commit -m "Initial commit: Add project files"

# Verify the commit
git log --oneline

Step 5: Connect to GitHub

# Add GitHub repository as remote origin
git remote add origin https://github.com/YourUsername/YourRepoName.git

# Verify remote was added
git remote -v

# Push your code to GitHub
git push -u origin main

If you get authentication error:

# Use token authentication
git remote set-url origin https://YourUsername:YourToken@github.com/YourUsername/YourRepoName.git

📥 Scenario B: Start from GitHub Repository

Step 1: Clone the Repository

# Clone repository to your computer
git clone https://github.com/Username/RepoName.git

# Navigate into the cloned folder
cd RepoName

# Check the status
git status

Step 2: Make Changes and Commit

# Make your changes to files
# Then add them to staging
git add .

# Commit your changes
git commit -m "Describe what you changed"

# Push to GitHub
git push

💼 Daily Workflow Commands

Basic Workflow (Use These Daily)

# 1. Check current status
git status

# 2. Add changes to staging
git add .                    # Add all changes
git add filename.txt         # Add specific file

# 3. Commit changes
git commit -m "Meaningful message describing changes"

# 4. Push to GitHub
git push

# 5. Get latest changes from GitHub
git pull

Checking Your Work

# See commit history
git log --oneline

# See what changed in files
git diff

# See branches
git branch

# See remotes
git remote -v

🌿 Working with Branches

Basic Branch Commands

# See all branches
git branch -a

# Create new branch
git checkout -b feature-name

# Switch to existing branch
git checkout main

# Merge branch into current branch
git merge feature-name

# Delete branch (after merging)
git branch -d feature-name

# Push new branch to GitHub
git push -u origin feature-name

Branch Workflow Example

# 1. Start from main branch
git checkout main
git pull

# 2. Create feature branch
git checkout -b add-login-feature

# 3. Work on your feature, make commits
git add .
git commit -m "Add login form"

# 4. Push feature branch
git push -u origin add-login-feature

# 5. Create Pull Request on GitHub
# (Done through web interface)

# 6. After PR is merged, clean up
git checkout main
git pull
git branch -d add-login-feature

🆘 Common Errors and Solutions

Error: "fatal: not a git repository"

Solution: You're not in a Git-initialized folder

git init

Error: "Updates were rejected"

Solution: Remote has changes you don't have locally

git pull origin main
# Resolve any conflicts, then:
git push

Error: "Authentication failed"

Solution: Set up authentication properly

# Use token in URL
git remote set-url origin https://username:token@github.com/username/repo.git

Error: "Please tell me who you are"

Solution: Configure Git user info

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

Accidentally committed wrong files

# Remove file from staging (before commit)
git reset filename.txt

# Remove file from last commit (after commit)
git reset --soft HEAD~1

📊 Essential Commands Quick Reference

Command Purpose When to Use
git init Start Git tracking New project
git clone <url> Copy repo from GitHub Starting with existing repo
git status See current state Check before committing
git add . Stage all changes Before committing
git commit -m "msg" Save snapshot After making changes
git push Upload to GitHub Share your work
git pull Download from GitHub Get latest changes
git log --oneline See history Review what happened
git branch List branches See all branches
git checkout -b name Create new branch Start new feature

🏁 Quick Start Template (For Future Projects)

New Project from Scratch:

# 1. Create project folder
mkdir MyNewProject
cd MyNewProject

# 2. Initialize Git
git init

# 3. Create .gitignore (copy from above)
# 4. Add your project files
# 5. Make first commit
git add .
git commit -m "Initial commit"

# 6. Create GitHub repo (through website)
# 7. Connect and push
git remote add origin https://github.com/username/MyNewProject.git
git push -u origin main

Working on Existing Project:

# 1. Clone repository
git clone https://github.com/username/project.git
cd project

# 2. Make changes
# 3. Commit and push
git add .
git commit -m "Your changes"
git push

📚 Your Learning Path

Beginner Level (You are here) ✅

  • Understand Git vs GitHub
  • Know basic commands
  • Can commit and push code
  • Can clone repositories

Intermediate Level (Next Goals) 🎯

  • Work with branches confidently
  • Understand merge conflicts and how to resolve them
  • Use pull requests for collaboration
  • Understand .gitignore patterns

Advanced Level (Future Goals) 🚀

  • Rebase vs merge strategies
  • Git hooks and automation
  • Advanced branching strategies (Git Flow)
  • Contributing to open source projects

🎓 Practice Exercise Using Your ParkerHub

Let's practice with your actual repository:

# 1. Navigate to your project
cd "C:\Users\akash\OneDrive\Desktop\coding\ParkerHub"

# 2. Check status
git status

# 3. Make a small change (add a comment to a file)
# 4. Commit the change
git add .
git commit -m "Add practice comment for Git learning"

# 5. Push to GitHub
git push

# 6. Check GitHub to see your change!

🔗 Helpful Resources for Beginners


💡 Pro Tips for Success

  1. Commit often - Small, frequent commits are better than large ones
  2. Write good commit messages - Describe WHAT and WHY, not HOW
  3. Use branches - Don't work directly on main for new features
  4. Pull before push - Always get latest changes first
  5. Backup important work - GitHub IS your backup!

Remember: Everyone was a beginner once. Don't be afraid to experiment - Git makes it very hard to permanently lose your work! 🎉


Created: September 20, 2025
For: Complete Git & GitHub beginners
Author: Based on ParkerHub project experience