DEV Community

Cover image for Getting Started with Git
Abhay Bhagat
Abhay Bhagat

Posted on • Edited on

Getting Started with Git

# 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"
Enter fullscreen mode Exit fullscreen mode

📦 Initialize Repository

git init # Initialize a Git repo 
git clone <url> # Clone a repo from GitHub
Enter fullscreen mode Exit fullscreen mode

📄 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
Enter fullscreen mode Exit fullscreen mode

🔁 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
Enter fullscreen mode Exit fullscreen mode

🌍 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
Enter fullscreen mode Exit fullscreen mode

🚫 Ignoring Files

  • Create a .gitignore file:
node_modules/ 
.env 
*.log
Enter fullscreen mode Exit fullscreen mode

🔄 Stashing

git stash # Save uncommitted changes 
git stash pop # Apply latest stash
Enter fullscreen mode Exit fullscreen mode

🔍 Useful Commands

git diff # Show changes 
git show <commit> # Show details of a commit 
git reset --hard <commit> # Roll back to a commit (DANGER!)
Enter fullscreen mode Exit fullscreen mode

✅ *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)