Git Memo

Git command cheat sheet/reference.

Runs locally

Customize Command Parameters

Type values below to dynamically customize variables inside the Git commands.

Setup

Configure global Git username

git config --global user.name "John Doe"
Setup

Configure global Git email address

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

Initialize a new local Git repository

git init
Setup

Clone a remote repository

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

Show state of working directory and staging area

git status
Commits

Stage file changes for next commit

git add index.js
Commits

Stage all current changes in the directory

git add .
Commits

Commit staged changes with a message

git commit -m "feat: add auth service"
Commits

Amend the last commit with a new message

git commit --amend -m "feat: add auth service"
Branching

List local branches

git branch
Branching

Create a new local branch

git branch feature/login
Branching

Switch to a different branch

git checkout feature/login
Branching

Create and switch to a new branch

git checkout -b feature/login
Branching

Delete a local branch

git branch -d feature/login
Branching

Merge a branch into the active branch

git merge feature/login
Stashing

Save modified and staged changes temporarily

git stash
Stashing

Restore the most recently stashed changes

git stash pop
Stashing

List all currently stashed changes

git stash list
Stashing

Discard the most recently stashed changes

git stash drop
History & Rebase

Show commit history simplified to one line per commit

git log --oneline
History & Rebase

Rebase active branch onto specified branch

git rebase feature/login
History & Rebase

Interactive rebase of last n commits

git rebase -i HEAD~3
Remotes

List remote connections and their URLs

git remote -v
Remotes

Push commits to origin remote repository branch

git push origin feature/login
Remotes

Fetch and merge remote changes into current branch

git pull origin feature/login
Undo & Reset

Undo last commit, keeping changes staged

git reset --soft HEAD~1
Undo & Reset

Undo last commit and discard all changes

git reset --hard HEAD~1
Undo & Reset

Discard changes in a file in working directory

git checkout -- index.js