my-notes

Git_Cheat_Sheet

1 min read

Git Cheat Sheet

Quick reference for essential commands.


πŸš€ Setup

git config --global user.name "Name"

Set your name.

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

Set your email.


πŸ“ Create Repository

git init

Initialize new repo.

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

Clone existing repo.


πŸ“ Basic Workflow

git status

Check status.

git add .

Stage all changes.

git commit -m "Message"

Commit changes.

git push

Push to remote.

git pull

Pull from remote.


🌿 Branches

git branch

List branches.

git checkout -b feature

Create and switch.

git switch main

Switch branch.

git merge feature

Merge branch.

git branch -d feature

Delete branch.


πŸ” View Changes

git diff

Unstaged changes.

git diff --staged

Staged changes.

git log --oneline

Compact history.


↩️ Undo

git restore file.txt

Discard changes.

git restore --staged file.txt

Unstage file.

git reset HEAD~1

Undo last commit (keep changes).

git reset --hard HEAD~1

⚠️ Undo last commit (discard changes).


πŸ’Ύ Stash

git stash

Save changes temporarily.

git stash pop

Restore stashed changes.

git stash list

List stashes.


🏷️ Tags

git tag v1.0.0

Create tag.

git push --tags

Push tags.


πŸ”§ Remote

git remote -v

View remotes.

git remote add origin url

Add remote.

git fetch

Download changes (no merge).


πŸ”€ Rebase

git rebase main

Rebase onto main.

git rebase -i HEAD~3

Interactive rebase.


πŸ“Š Quick Reference Table

Task Command
Init git init
Clone git clone url
Add all git add .
Commit git commit -m "msg"
Push git push
Pull git pull
Status git status
Log git log --oneline
Branch git checkout -b name
Merge git merge name
Stash git stash
Diff git diff


#git #cheatsheet #reference #quick

Built with mdgarden