Skip to content

Abdelrhman941/Version_Control_Learn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Complete Linux, Git & GitHub Reference Guide

A comprehensive, organized reference for command-line tools, version control, and collaboration


πŸ“‹ Table of Contents

  1. Linux Command Line Essentials
  2. Git Version Control
  3. GitHub Workflows
  4. Quick Reference Cheat Sheet
  5. Visual Mind Map

🐧 Linux Command Line Essentials

πŸ“ File and Directory Operations

Navigation Commands

pwd                    # Print working directory
ls                     # List directory contents
ls -la                 # List with details and hidden files
ls -lh                 # List with human-readable file sizes
cd /path/to/directory  # Change directory
cd ~                   # Go to home directory
cd ..                  # Go up one directory
cd -                   # Go to previous directory

File Creation and Manipulation

touch filename         # Create empty file
mkdir dirname          # Create directory
mkdir -p path/to/dir   # Create nested directories
cp source dest         # Copy file
cp -r source dest      # Copy directory recursively
mv source dest         # Move/rename file or directory
rm filename            # Remove file
rm -r dirname          # Remove directory recursively
rm -rf dirname         # Force remove directory
rmdir dirname          # Remove empty directory

File Content Operations

cat filename           # Display file content
head filename          # Show first 10 lines
head -n 20 filename    # Show first 20 lines
tail filename          # Show last 10 lines
tail -f filename       # Follow file changes in real-time
less filename          # View file with pagination
more filename          # View file page by page
wc filename            # Word, line, character count
wc -l filename         # Line count only

πŸ” Search and Text Processing

Finding Files and Content

find /path -name "pattern"     # Find files by name
find . -type f -name "*.txt"   # Find all .txt files
find . -type d -name "docs"    # Find directories named "docs"
locate filename                # Quick file location search
which command                  # Find command location
whereis command                # Find command and manual pages

Text Search and Processing

grep "pattern" filename        # Search for pattern in file
grep -r "pattern" directory    # Recursive search in directory
grep -i "pattern" filename     # Case-insensitive search
grep -n "pattern" filename     # Show line numbers
grep -v "pattern" filename     # Show lines NOT matching pattern
awk '{print $1}' filename      # Print first column
sed 's/old/new/g' filename     # Replace text
sort filename                  # Sort file contents
uniq filename                  # Remove duplicate lines
cut -d',' -f1 filename         # Extract first column (CSV)

πŸ” Permissions and User Management

File Permissions

chmod 755 filename             # Set permissions (rwxr-xr-x)
chmod +x filename              # Add execute permission
chmod u+w filename             # Add write permission for user
chmod g-r filename             # Remove read permission for group
chmod o+r filename             # Add read permission for others
chown user:group filename      # Change file ownership
chown -R user:group directory  # Change ownership recursively

Permission Values

Permission Binary Decimal
--- 000 0
--x 001 1
-w- 010 2
-wx 011 3
r-- 100 4
r-x 101 5
rw- 110 6
rwx 111 7

User Information

whoami                         # Current username
id                             # User and group IDs
groups                         # User's groups
w                              # Who is logged in
last                           # Last login history
su username                    # Switch user
sudo command                   # Run command as superuser

βš™οΈ System Information and Process Management

System Information

uname -a                       # System information
lsb_release -a                 # Linux distribution info
df -h                          # Disk space usage
du -sh directory               # Directory size
free -h                        # Memory usage
uptime                         # System uptime
date                           # Current date and time
cal                            # Calendar

Process Management

ps aux                         # List all processes
ps aux | grep process_name     # Find specific process
top                            # Real-time process monitor
htop                           # Enhanced process monitor
kill PID                       # Kill process by PID
killall process_name           # Kill process by name
jobs                           # List active jobs
bg                             # Send job to background
fg                             # Bring job to foreground
nohup command &                # Run command immune to hangups

Network Commands

ping hostname                  # Test network connectivity
wget URL                       # Download file from web
curl URL                       # Transfer data from/to server
ssh user@hostname              # Secure shell login
scp file user@host:/path       # Secure copy over network
netstat -tulpn                 # Network connections

🎯 Git Version Control

🏁 Git Setup and Configuration

Initial Setup

# Set up user identity
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

# Set default editor
git config --global core.editor "nano"  # or vim, code, etc.

# View all configurations
git config --list

# View specific configuration
git config user.name

Repository Initialization

git init                       # Initialize new repository
git clone <repository-url>     # Clone existing repository
git clone <url> <folder-name>  # Clone to specific folder

πŸ“¦ Basic Git Workflow

Staging and Committing

# Check status
git status                     # Check repository status
git status -s                  # Short status format

# Add files to staging
git add filename               # Add specific file
git add .                      # Add all files in current directory
git add -A                     # Add all files (including deletions)
git add *.txt                  # Add all .txt files

# Commit changes
git commit -m "Commit message" # Commit with message
git commit -am "Message"       # Add and commit tracked files
git commit                     # Open editor for commit message
git commit --amend             # Modify last commit

Viewing Changes and History

# View differences
git diff                       # Show unstaged changes
git diff --staged              # Show staged changes
git diff HEAD~1                # Compare with previous commit
git diff commit1..commit2      # Compare two commits

# View commit history
git log                        # Show commit history
git log --oneline              # Compact log format
git log --graph                # Show branch graph
git log --oneline --decorate --graph --all  # Detailed graph
git show <commit-hash>         # Show specific commit details

File Operations

git ls-files                   # List tracked files
git rm filename                # Remove file from git and filesystem
git rm --cached filename       # Remove from git but keep file
git mv oldname newname         # Rename/move file

🌿 Branching and Merging

Branch Management

# Create and manage branches
git branch                     # List local branches
git branch -a                  # List all branches (local + remote)
git branch branch-name         # Create new branch
git branch -d branch-name      # Delete branch (safe)
git branch -D branch-name      # Force delete branch
git branch -m old-name new-name # Rename branch

# Switch branches
git switch branch-name         # Switch to branch (Git 2.23+)
git checkout branch-name       # Switch to branch (older method)
git checkout -b branch-name    # Create and switch to branch
git switch -c branch-name      # Create and switch to branch (Git 2.23+)

Merging

# Merge branches
git merge branch-name          # Merge branch into current branch
git merge --no-ff branch-name  # Force merge commit
git merge --squash branch-name # Squash merge

# Check merge status
git branch --merged            # Show merged branches
git branch --no-merged         # Show unmerged branches

Rebasing

git rebase branch-name         # Rebase current branch onto branch-name
git rebase -i HEAD~3           # Interactive rebase (last 3 commits)
git rebase --continue          # Continue rebase after resolving conflicts
git rebase --abort             # Abort rebase operation

πŸ”„ Undoing Changes

Unstaging and Reverting

# Unstage files
git reset filename             # Unstage specific file
git reset                      # Unstage all files
git reset --hard               # Reset to last commit (lose changes)
git reset --soft HEAD~1        # Undo last commit, keep changes staged
git reset --mixed HEAD~1       # Undo last commit, unstage changes
git reset --hard HEAD~1        # Undo last commit, lose changes

# Revert commits
git revert commit-hash         # Create new commit that undoes changes
git revert HEAD                # Revert last commit

# Restore files
git restore filename           # Restore file to last committed state
git restore --staged filename  # Unstage file (Git 2.23+)
git checkout -- filename      # Restore file (older method)

Stashing Changes

git stash                      # Stash current changes
git stash push -m "message"    # Stash with message
git stash list                 # List all stashes
git stash pop                  # Apply and remove latest stash
git stash apply                # Apply latest stash without removing
git stash apply stash@{2}      # Apply specific stash
git stash drop stash@{2}       # Delete specific stash
git stash clear                # Delete all stashes

πŸ™ GitHub Workflows

🌐 Remote Repository Management

Working with Remotes

# View remotes
git remote                     # List remote names
git remote -v                  # List remotes with URLs
git remote show origin         # Show remote details

# Add and manage remotes
git remote add origin <url>    # Add remote repository
git remote rename origin upstream # Rename remote
git remote remove origin       # Remove remote
git remote set-url origin <new-url> # Change remote URL

Push and Pull Operations

# Push changes
git push origin branch-name    # Push branch to remote
git push -u origin branch-name # Push and set upstream
git push --all origin          # Push all branches
git push --tags                # Push all tags
git push --force               # Force push (dangerous!)
git push --force-with-lease    # Safer force push

# Pull changes
git pull                       # Fetch and merge from upstream
git pull origin branch-name    # Pull specific branch
git pull --rebase              # Pull with rebase instead of merge

# Fetch changes
git fetch                      # Download objects and refs
git fetch origin               # Fetch from specific remote
git fetch --all                # Fetch from all remotes

🏷️ Tags and Releases

Tagging

# Create tags
git tag v1.0.0                 # Create lightweight tag
git tag -a v1.0.0 -m "Version 1.0.0" # Create annotated tag
git tag -a v1.0.0 commit-hash  # Tag specific commit

# List and manage tags
git tag                        # List all tags
git tag -l "v1.*"              # List tags matching pattern
git show v1.0.0                # Show tag details
git tag -d v1.0.0              # Delete local tag
git push origin --delete v1.0.0 # Delete remote tag

# Push tags
git push origin v1.0.0         # Push specific tag
git push origin --tags         # Push all tags

GitHub Specific Operations

# Fork workflow
git remote add upstream <original-repo-url>
git fetch upstream
git checkout main
git merge upstream/main

# Branch management for PRs
git checkout -b feature/new-feature
# Make changes, commit
git push -u origin feature/new-feature
# Create PR on GitHub
# After PR merge:
git checkout main
git pull origin main
git branch -d feature/new-feature
git push origin --delete feature/new-feature

πŸ”§ Advanced Git Features

Git Aliases

# Create useful aliases
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
git config --global alias.graph 'log --oneline --decorate --graph --all'

# Usage: git st instead of git status

Git Hooks

# Hook locations
ls .git/hooks/                 # View available hooks

# Common hooks:
# - pre-commit: Run before commit
# - post-commit: Run after commit
# - pre-push: Run before push
# - post-receive: Run after receiving push

Submodules

# Add submodule
git submodule add <repository-url> <path>

# Initialize and update submodules
git submodule init
git submodule update
git submodule update --recursive

# Clone repository with submodules
git clone --recursive <repository-url>

πŸ“„ Quick Reference Cheat Sheet

πŸš€ Most Used Commands

Category Command Description
Linux Basics pwd Show current directory
ls -la List files with details
cd directory Change directory
mkdir dirname Create directory
rm -rf dirname Remove directory
chmod 755 file Set file permissions
Git Basics git status Check repository status
git add . Stage all changes
git commit -m "msg" Commit with message
git push origin main Push to remote
git pull Pull latest changes
Git Branching git branch List branches
git switch -c branch Create and switch branch
git merge branch Merge branch
git branch -d branch Delete branch
Git Undo git reset filename Unstage file
git restore filename Restore file
git revert HEAD Revert last commit
git stash Temporarily save changes

🎯 Git Workflow Pattern

# 1. Start new feature
git switch -c feature/new-feature

# 2. Make changes and commit
git add .
git commit -m "Add new feature"

# 3. Push to remote
git push -u origin feature/new-feature

# 4. Create Pull Request on GitHub

# 5. After merge, cleanup
git switch main
git pull origin main
git branch -d feature/new-feature

🧠 Visual Mind Map

🌳 Linux, Git & GitHub Knowledge Tree

πŸ“š LINUX, GIT & GITHUB MASTERY
|
β”œβ”€β”€ 🐧 LINUX COMMAND LINE
β”‚   β”œβ”€β”€ πŸ“ File Operations
β”‚   β”‚   β”œβ”€β”€ Navigation      (pwd, ls, cd)
β”‚   β”‚   β”œβ”€β”€ Creation        (touch, mkdir)
β”‚   β”‚   β”œβ”€β”€ Manipulation    (cp, mv, rm)
β”‚   β”‚   └── Content         (cat, head, tail, less)
|   |
β”‚   β”œβ”€β”€ πŸ” Search & Text
β”‚   β”‚   β”œβ”€β”€ Find Files      (find, locate, which)
β”‚   β”‚   β”œβ”€β”€ Search Content  (grep, awk, sed)
β”‚   β”‚   └── Process Text    (sort, uniq, cut)
|   |
β”‚   β”œβ”€β”€ πŸ” Permissions
β”‚   β”‚   β”œβ”€β”€ File Permission (chmod)
β”‚   β”‚   β”œβ”€β”€ Ownership       (chown)
β”‚   β”‚   └── User Management (whoami, su, sudo)
|   |
β”‚   └── βš™οΈ System
β”‚       β”œβ”€β”€ Info            (uname, df, free, uptime)
β”‚       β”œβ”€β”€ Processes       (ps, top, kill)
β”‚       └── Network         (ping, wget, ssh)
β”‚
β”œβ”€β”€ 🎯 GIT VERSION CONTROL
β”‚   β”œβ”€β”€ 🏁 Setup
β”‚   β”‚   β”œβ”€β”€ Config          (git config)
β”‚   β”‚   β”œβ”€β”€ Init            (git init)
β”‚   β”‚   └── Clone           (git clone)
|   |
β”‚   β”œβ”€β”€ πŸ“¦ Basic Workflow
β”‚   β”‚   β”œβ”€β”€ Status          (git status)
β”‚   β”‚   β”œβ”€β”€ Staging         (git add)
β”‚   β”‚   β”œβ”€β”€ Committing      (git commit)
β”‚   β”‚   └── History         (git log, git diff)
|   |
β”‚   β”œβ”€β”€ 🌿 Branching
β”‚   β”‚   β”œβ”€β”€ Create          (git branch, git switch)
β”‚   β”‚   β”œβ”€β”€ Merge           (git merge)
β”‚   β”‚   β”œβ”€β”€ Rebase          (git rebase)
β”‚   β”‚   └── Delete          (git branch -d)
|   |
β”‚   β”œβ”€β”€ πŸ”„ Undoing
β”‚   β”‚   β”œβ”€β”€ Reset           (git reset)
β”‚   β”‚   β”œβ”€β”€ Revert          (git revert)
β”‚   β”‚   β”œβ”€β”€ Restore         (git restore)
β”‚   β”‚   └── Stash           (git stash)
|   |
β”‚   └── πŸ”§ Advanced
β”‚       β”œβ”€β”€ Aliases
β”‚       β”œβ”€β”€ Hooks
β”‚       └── Submodules
β”‚
└── πŸ™ GITHUB WORKFLOWS
    β”œβ”€β”€ 🌐 Remotes
    β”‚   β”œβ”€β”€ Add/Manage (git remote)
    β”‚   β”œβ”€β”€ Push            (git push)
    β”‚   β”œβ”€β”€ Pull            (git pull)
    β”‚   └── Fetch           (git fetch)
    |   
    β”œβ”€β”€ 🏷️ Tags & Releases
    β”‚   β”œβ”€β”€ Create Tags     (git tag)
    β”‚   β”œβ”€β”€ Push Tags
    β”‚   └── GitHub Releases
    |   
    └── πŸ”„ Collaboration
        β”œβ”€β”€ Fork Workflow
        β”œβ”€β”€ Pull Requests
        β”œβ”€β”€ Code Review
        └── Issue Tracking

πŸ›€οΈ Learning Roadmap

🎯 Beginner Path (1-2 weeks)

  1. Linux Basics

    • Master navigation (pwd, ls, cd)
    • Learn file operations (touch, mkdir, cp, mv, rm)
    • Understand basic permissions (chmod, chown)
  2. Git Fundamentals

    • Setup Git (git config)
    • Learn basic workflow (init, add, commit, status)
    • Understand history (git log, git diff)
  3. GitHub Basics

    • Create account and first repository
    • Learn push/pull (git push, git pull)
    • Clone existing repositories

πŸš€ Intermediate Path (2-4 weeks)

  1. Advanced Linux

    • Master text processing (grep, awk, sed)
    • Learn system monitoring (ps, top, netstat)
    • Understand pipes and redirection
  2. Git Branching

    • Create and switch branches (git branch, git switch)
    • Merge strategies (git merge, git rebase)
    • Resolve conflicts
  3. GitHub Collaboration

    • Fork repositories
    • Create Pull Requests
    • Code review process

πŸ† Advanced Path (1-2 months)

  1. Linux Mastery

    • Shell scripting
    • Process management
    • Network troubleshooting
  2. Git Advanced

    • Interactive rebase
    • Git hooks
    • Submodules
  3. GitHub Enterprise

    • GitHub Actions (CI/CD)
    • Issue tracking
    • Project management

πŸ’‘ Pro Tips

πŸ”₯ Linux Power Tips

  • Use history | grep command to find previously used commands
  • Create aliases for frequently used commands: alias ll='ls -la'
  • Use ctrl+r for reverse search in command history
  • Master tab completion for faster typing

⚑ Git Power Tips

  • Use git commit --amend to fix the last commit message
  • Create meaningful commit messages (what and why)
  • Use git stash when switching contexts quickly
  • Set up aliases for commonly used Git commands

🌟 GitHub Power Tips

  • Use issue templates for consistent reporting
  • Set up branch protection rules
  • Use GitHub CLI (gh) for command-line GitHub operations
  • Enable GitHub Pages for project documentation

πŸ“š Additional Resources


πŸŽ‰ Happy Learning! Remember: Practice makes perfect. Start with the basics and gradually build up your skills.

About

study Git and command lines

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published