Python Java C++ HTML CSS Bootstrap JavaScript jQuery AngularJS React Node.js TypeScript Django NumPy Pandas Matplotlib Seaborn Machine Learning Deep Learning Decipher XML

Introduction to Git & GitHub

Git is a distributed version control system. GitHub is a cloud-based platform for hosting and collaborating on Git repositories.

Git and GitHub are essential for collaborative coding, version tracking, and project management.

GitHub Basics

Creating a Repository

# Create local repository
git init

# Create remote repository on GitHub
# Then link local repo
git remote add origin <repo-url>
      

Cloning & Pulling

# Clone a repository
git clone <repo-url>

# Pull latest changes
git pull origin main
      

Branching & Merging

# List branches
git branch

# Create new branch
git branch feature1

# Switch to branch
git checkout feature1

# Merge branch
git checkout main
git merge feature1
      

Deleting Branch

git branch -d feature1
      

Committing & Pushing Changes

# Stage changes
git add .

# Commit changes
git commit -m "Added new feature"

# Push to remote
git push origin main
      

Collaboration on GitHub

Pull Requests (PR)

Use PRs to review and merge code from different branches or contributors.

Forking & Cloning

Fork repositories to make independent changes, then create PRs to original repo.

Resolving Conflicts

# During merge conflicts
git status
# Edit files to resolve
git add resolved_file
git commit -m "Resolved conflict"
git push
      

Advanced GitHub Features

Reverting Commits

git revert <commit-id>
      

Reset & Checkout

# Soft reset
git reset --soft HEAD~1

# Hard reset (careful!)
git reset --hard HEAD~1
      

Tags & Releases

# Create a tag
git tag v1.0

# Push tags
git push origin v1.0
      

GitHub Actions

Automate workflows like testing, deployment, CI/CD pipelines using Actions.