Skip to content

Latest commit

Β 

History

History
147 lines (99 loc) Β· 2.32 KB

git_cheatsheet.md

File metadata and controls

147 lines (99 loc) Β· 2.32 KB

🧠 Git & GitHub Beginner Cheat Sheet

A simple, beginner-friendly cheat sheet for everyday Git and GitHub commands.


πŸ”§ 1. Initial Setup

git config --global user.name "Your Name"
# Sets your name for all commits

git config --global user.email "you@example.com"
# Sets your email for all commits

git config --list
# Lists all current Git config settings

πŸ“ 2. Starting a Project

git init
# Creates a new Git repo in the current folder

git clone https://github.com/user/repo.git
# Copies a GitHub repo to your local system

πŸ“„ 3. Checking Status

git status
# Shows which files are new, modified, staged, or ignored

βž• 4. Adding Files

git add filename.ext
# Stages a single file

git add .
# Stages ALL modified and new files in the current folder

βœ… 5. Committing Changes

git commit -m "Describe what you did"
# Saves your staged changes with a message

Example:

git commit -m "Fixed login bug and added validation"

πŸ”„ 6. Pulling and Pushing Code

git pull
# Gets the latest changes from the remote repo (e.g., GitHub)

git push
# Sends your committed changes to the remote repo

🌿 7. Working with Branches

git branch
# Lists all branches in your local repo

git branch new-branch
# Creates a new branch (but does NOT switch to it)

git checkout branch-name
# Switches to an existing branch

git checkout -b new-branch
# Creates AND switches to a new branch

git merge branch-name
# Merges another branch into your current one

πŸ”™ 8. Undoing Changes

git reset filename.ext
# Unstages a file (keeps the changes)

git checkout -- filename.ext
# Reverts the file to its last committed state (loses changes)

git reset --hard
# WARNING: Resets ALL changes and staging β€” use carefully!

πŸ“œ 9. Viewing History

git log
# Shows full commit history with author, date, message

git log --oneline
# Shows a compact one-line-per-commit history

πŸ› οΈ 10. Everyday Workflow

git status
git add .
git commit -m "Your message"
git pull
git push

πŸ’‘ Bonus Tips

  • Always use git status to know what’s going on.
  • Use meaningful commit messages.
  • Use branches for new features or fixes.
  • Pull before you push to avoid conflicts.