Skip to main content

Git Commands

Essential Git commands for version control

Version Control

Setup & Config

git init

Initialize a new Git repository

git clone <url>

Clone a repository

git config --global user.name "Name"

Set username

git config --global user.email "email"

Set email

Basic Commands

git status

Check working directory status

git add <file>

Stage a file

git add .

Stage all changes

git commit -m "message"

Commit with message

git push

Push to remote

git pull

Pull from remote

Branching

git branch

List branches

git branch <name>

Create new branch

git checkout <branch>

Switch to branch

git checkout -b <name>

Create and switch to branch

git merge <branch>

Merge branch into current

git branch -d <name>

Delete branch

History & Diff

git log

View commit history

git log --oneline

Compact commit history

git diff

Show unstaged changes

git diff --staged

Show staged changes

git show <commit>

Show commit details

Undo & Reset

git restore <file>

Discard changes in file

git reset HEAD <file>

Unstage a file

git reset --soft HEAD~1

Undo last commit, keep changes

git reset --hard HEAD~1

Undo last commit, discard changes

git revert <commit>

Create new commit that undoes changes

Stash

git stash

Stash current changes

git stash list

List all stashes

git stash pop

Apply and remove latest stash

git stash apply

Apply latest stash, keep it

git stash drop

Remove latest stash

Privacy-First Developer Toolkits - 35+ Browser-Based Tools