A complete step-by-step guide for beginners to understand and use Git with GitHub.
- Git is a version control system that tracks changes in your code
- It runs locally on your computer
- Keeps a history of all your code changes
- Allows you to revert to previous versions
- GitHub is a cloud service that hosts Git repositories
- Stores your code online
- Allows collaboration with others
- Provides backup for your code
Think of it like: Git is like a diary for your code (local), and GitHub is like a library where you store copies of your diary (online).
- A folder that contains your project and its Git history
- Can be local (on your computer) or remote (on GitHub)
- Different versions of your code
mainormaster- the primary branch- You can create other branches for features or experiments
- A snapshot of your project at a specific time
- Like saving a checkpoint in a game
- Push: Send your local changes to GitHub
- Pull: Download changes from GitHub to your local computer
Download and install Git from: https://git-scm.com/
# Set your name (will appear in commits)
git config --global user.name "Your Name"
# Set your email (should match your GitHub email)
git config --global user.email "your.email@example.com"
# Check your configuration
git config --listExample:
git config --global user.name "akashdip2001"
git config --global user.email "akashdipabc@abc.in"When you have code on your computer and want to upload it to GitHub.
- Go to https://github.com
- Click the "+" button → "New repository"
- Enter repository name (e.g., "MyProject")
- Choose Public or Private
- Don't initialize with README (since you have local code)
- Click "Create repository"
# Navigate to your project folder
cd "C:\path\to\your\project"
# Initialize Git repository
git init
# Check status (see what files Git is tracking)
git status# Create .gitignore file (tells Git which files to ignore)
# For Python/Django projects:
echo "# Python
__pycache__/
*.py[cod]
*.so
.Python
env/
venv/
*.log
db.sqlite3
.env
.vscode/
.idea/" > .gitignore# Add all files to staging area
git add .
# Check what's been added
git status# Create first commit with a message
git commit -m "Initial commit: Add project files"# Add GitHub repository as remote origin
git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git
# Verify remote was added
git remote -vExample:
git remote add origin https://github.com/akashdip2001/ParkerHub.git# Push your code to GitHub
git push -u origin main
# If your default branch is master:
git push -u origin masterWhen you want to download an existing GitHub repository to your computer.
# Navigate to where you want the project
cd "C:\Users\YourName\Desktop\Projects"
# Clone the repository
git clone https://github.com/USERNAME/REPOSITORY_NAME.git
# Enter the project folder
cd REPOSITORY_NAMEExample:
git clone https://github.com/akashdip2001/ParkerHub.git
cd ParkerHubOnce your repository is set up, here's your daily workflow:
# See what files have changed
git status# Add specific file
git add filename.py
# Add all changes
git add .
# Add all Python files
git add *.py# Commit with descriptive message
git commit -m "Add user authentication feature"
# Examples of good commit messages:
git commit -m "Fix login bug"
git commit -m "Update README with installation instructions"
git commit -m "Add contact form to website"# Send changes to GitHub
git push# Get latest changes from GitHub
git pull| Command | Purpose | Example |
|---|---|---|
git init |
Initialize Git in folder | git init |
git status |
Check current status | git status |
git add |
Stage files for commit | git add . |
git commit |
Save changes locally | git commit -m "message" |
git push |
Upload to GitHub | git push |
git pull |
Download from GitHub | git pull |
git clone |
Copy repository locally | git clone <url> |
git branch |
List branches | git branch |
git checkout |
Switch branches | git checkout main |
git log |
View commit history | git log --oneline |
# Create new branch
git branch feature-login
# Switch to branch
git checkout feature-login
# Create and switch in one command
git checkout -b feature-login# Switch to main branch
git checkout main
# Merge feature branch into main
git merge feature-login
# Delete branch after merging
git branch -d feature-loginLet's say you have a Python project called "MyWebApp":
# 1. Navigate to your project
cd "C:\Users\akash\Desktop\MyWebApp"
# 2. Initialize Git
git init
# 3. Create .gitignore
echo "__pycache__/
*.pyc
.env
venv/" > .gitignore
# 4. Add all files
git add .
# 5. First commit
git commit -m "Initial commit: Add MyWebApp project"
# 6. Connect to GitHub (create repo on GitHub first)
git remote add origin https://github.com/akashdip2001/MyWebApp.git
# 7. Push to GitHub
git push -u origin main
# 8. Later, when you make changes:
# Edit some files...
git add .
git commit -m "Add user registration feature"
git pushProblem: You're not in a Git-initialized folder Solution:
git initProblem: Remote has changes you don't have locally Solution:
git pull origin main
# Then push again
git pushProblem: Local branch not connected to remote Solution:
git push --set-upstream origin mainProblem: Same file edited in different ways Solution:
- Open conflicted files
- Look for
<<<<<<<,=======,>>>>>>>markers - Choose which version to keep
- Remove conflict markers
git add .andgit commit
- Uses your GitHub username and password/token
- GitHub now requires Personal Access Token instead of password
- GitHub → Settings → Developer settings → Personal access tokens
- Generate new token
- Select scopes (repo permissions)
- Use token as password when prompted
- More secure, no need to enter credentials repeatedly
- Requires SSH key setup
✅ Good:
- "Add user login functionality"
- "Fix database connection error"
- "Update README with setup instructions"
❌ Bad:
- "fix"
- "update"
- "asdf"
- After completing a feature
- After fixing a bug
- Before switching branches
- At the end of each work session
Always ignore:
- Build files (
__pycache__/,node_modules/) - Environment files (
.env,venv/) - IDE files (
.vscode/,.idea/) - OS files (
.DS_Store,Thumbs.db) - Database files (
*.sqlite3)
For future projects, here's your quick setup:
# 1. Create project folder
mkdir MyNewProject
cd MyNewProject
# 2. Initialize Git
git init
# 3. Create basic files
echo "# MyNewProject" > README.md
echo "*.log
__pycache__/
.env" > .gitignore
# 4. First commit
git add .
git commit -m "Initial commit: Setup project structure"
# 5. Create GitHub repo (on GitHub website)
# 6. Connect and push
git remote add origin https://github.com/yourusername/MyNewProject.git
git push -u origin main- Understand Git basics
- Connect local code to GitHub
- Basic add, commit, push workflow
- Branching and merging
- Resolving conflicts
- Using GitHub Issues and Pull Requests
- Collaborating with others
- Git workflows (GitFlow, GitHub Flow)
- Rebasing and advanced Git commands
- CI/CD with GitHub Actions
- Code reviews and team collaboration
- Git Documentation: https://git-scm.com/doc
- GitHub Guides: https://guides.github.com/
- Interactive Git Tutorial: https://learngitbranching.js.org/
- Git Cheat Sheet: https://education.github.com/git-cheat-sheet-education.pdf
Remember: Git seems complex at first, but with practice, these commands become second nature. Start with the basic workflow (add → commit → push) and gradually learn more advanced features.
Created: September 20, 2025