# Git and Github
🧠 Git & *GitHub*
📁 Git Basics
- Git
is a version control system to track changes in code.
- GitHub
is a remote hosting service for Git repositories.
🔧 Git Setup
git config --global user.name "Your Name" git config --global user.email "you@example.com"
📦 Initialize Repository
git init # Initialize a Git repo
git clone <url> # Clone a repo from GitHub
📄 Basic Commands
git status # Check status
git add <file> # Stage file
git add . # Stage all changes
git commit -m "message" # Commit staged changes
git log # View commit history
🔁 Branching
git branch # List branches
git branch <name> # Create new branch
git checkout <name> # Switch branch
git checkout -b <name> # Create + switch
git merge <branch> # Merge into current
🌍 Remote Repos
git remote add origin <url> # Add remote
git push -u origin main # Push initial branch
git push # Push changes
git pull # Pull changes
git clone <url> # Clone remote repo
🚫 Ignoring Files
- Create a .gitignore file:
node_modules/
.env
*.log
🔄 Stashing
git stash # Save uncommitted changes
git stash pop # Apply latest stash
🔍 Useful Commands
git diff # Show changes
git show <commit> # Show details of a commit
git reset --hard <commit> # Roll back to a commit (DANGER!)
✅ *GitHub Workflow (Typical)*
- Fork repository
- git clone the fork
- Create a new branch
- Make changes, commit
- Push to GitHub
- Open a Pull Request (PR)
📌 *Helpful Tips*
- Always pull before pushing
- Write clear commit messages
- Use .gitignore to avoid committing sensitive files
Top comments (0)