Git Complete Guide

Everything you need to start using Git and GitHub

1. Install & Configure Git

Check Git Version

git --version

Configure Username & Email

git config --global user.name "Your Name"

git config --global user.email "you@example.com"

2. Create Repository

Initialize Git

git init

Clone Existing Repository

git clone https://github.com/user/repo.git

3. Basic Workflow

Check Status

git status

Add Files

git add .
git add filename.txt

Create Commit

git commit -m "Initial commit"

View History

git log
git log --oneline

4. Branches

Create Branch

git branch feature

Switch Branch

git checkout feature

git switch feature

Create & Switch

git checkout -b feature

git switch -c feature

Delete Branch

git branch -d feature

5. Merge Branches

git merge feature

6. GitHub Remotes

Add Remote

git remote add origin https://github.com/user/repo.git

View Remote

git remote -v

7. Push & Pull

Push Code

git push -u origin main

git push

Pull Updates

git pull

Fetch Updates

git fetch

8. Undo Changes

git restore file.txt

git restore --staged file.txt

git reset HEAD~1

9. Stash

git stash
git stash list
git stash pop

10. Tags

git tag v1.0
git push origin v1.0

Git Cheat Sheet

Task Command
Status git status
Add Files git add .
Commit git commit -m "message"
Push git push
Pull git pull
New Branch git checkout -b branch
Merge git merge branch