Git-Github


1. SETUP & CONFIGURATION

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

Sets commit username

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

Sets commit email identity

git config --list

View configuration values

git help <command>

Help documentation


2. REPOSITORY BASICS

git init

Create new repository

git clone <url>

Clone remote repository

git status

Check file status


3. STAGING & UNSTAGING

git add <file>

Stage selected file

git add .

Stage all changes

git restore <file>

Discard working directory changes


4. COMMIT

git commit -m "message"

Commit staged changes

git commit -am "message"

Stage + commit tracked files


Git Workflow

5. BRANCHING

git branch

List branches

git branch <name>

Create branch

git checkout <name>

Switch branch

git checkout -b <name>

Create + switch

git switch <name>

Modern branch switch

git switch -c <name>

Create + switch (modern)


6. MERGE & REBASE

git merge <branch>

Merge branch

git rebase <branch>

Rebase onto branch

git merge --abort

Cancel merge


7. REMOTE OPERATIONS

git remote -v

List remotes

git remote add origin <url>

Add remote repo

git push -u origin <branch>

Push and set upstream

git push

Push commits

git pull

Pull + merge

git fetch

Fetch without merging


Git and GitHub

8. STASH

git stash

Save uncommitted changes

git stash pop

Restore stashed changes

git stash list

View stash list


9. LOGS & HISTORY

git log

View commit history

git log --oneline --graph --decorate

Compact visual log

git show <commit>

Show commit details

git diff

Compare changes


10. UNDO & FIX

git reset --soft HEAD~1

Undo commit (keep staged)

git reset --hard HEAD~1

Undo commit (remove changes)

git revert <commit>

Safely undo commit