Git Command Reference

Basic

git init

Initialize a new Git repository

git clone [url]

Clone a repository from a URL

git status

Show the working tree status

git add [file]

Add file contents to the staging area

Example
git add README.md
git add .

Add all changes to the staging area

git commit -m "[message]"

Record changes to the repository

Example
git commit -m "Fix bug"
git push

Update remote refs with local commits

git pull

Fetch and merge changes from remote

Branching

git branch

List all local branches

git branch [name]

Create a new branch

Example
git branch feature-login
git branch -d [name]

Delete a branch

Example
git branch -d old-feature
git checkout [branch]

Switch to a branch

Example
git checkout main
git checkout -b [name]

Create and switch to a new branch

Example
git checkout -b feature-x
git switch [branch]

Switch branches (newer syntax)

Example
git switch develop
git switch -c [name]

Create and switch to a new branch

Example
git switch -c hotfix

Merging

git merge [branch]

Merge a branch into the current branch

Example
git merge feature-x
git merge --no-ff [branch]

Merge with a merge commit

Example
git merge --no-ff develop
git merge --abort

Abort the current merge conflict resolution

git rebase [branch]

Reapply commits on top of another base

Example
git rebase main
git rebase -i [commit]

Interactive rebase

Example
git rebase -i HEAD~3

Remote

git remote

List remote repositories

git remote -v

List remote repositories with URLs

git remote add [name] [url]

Add a new remote

Example
git remote add origin https://github.com/user/repo.git
git remote remove [name]

Remove a remote

Example
git remote remove origin
git fetch

Download objects and refs from remote

git fetch [remote]

Fetch from specific remote

Example
git fetch origin
git push -u [remote] [branch]

Push and set upstream

Example
git push -u origin main
git push --force

Force push (use with caution!)

Stash

git stash

Stash the changes in a dirty working directory

git stash list

List all stashed changes

git stash pop

Apply and remove the latest stash

git stash apply

Apply the latest stash without removing it

git stash drop

Remove the latest stash

git stash clear

Remove all stashed entries

git stash save "[message]"

Stash with a message

Example
git stash save "WIP: feature"

History

git log

Show commit logs

git log --oneline

Show commit logs in compact format

git log --graph

Show commit logs with ASCII graph

git log -n [number]

Show last N commits

Example
git log -n 5
git diff

Show changes between commits, commit and working tree, etc

git diff [branch1] [branch2]

Show differences between branches

Example
git diff main develop
git show [commit]

Show various types of objects

Example
git show HEAD

Undoing

git reset [file]

Unstage a file

Example
git reset README.md
git reset --soft HEAD~1

Undo last commit, keep changes staged

git reset --hard HEAD~1

Undo last commit and discard changes

git revert [commit]

Create a new commit that undoes changes

Example
git revert abc123
git checkout -- [file]

Discard changes in working directory

Example
git checkout -- index.html
git restore [file]

Restore working tree files

Example
git restore README.md
git clean -fd

Remove untracked files and directories

Tags

git tag

List all tags

git tag [name]

Create a lightweight tag

Example
git tag v1.0.0
git tag -a [name] -m "[message]"

Create an annotated tag

Example
git tag -a v1.0.0 -m "Release 1.0"
git tag -d [name]

Delete a tag

Example
git tag -d v1.0.0
git push [remote] [tag]

Push a tag to remote

Example
git push origin v1.0.0
git push [remote] --tags

Push all tags to remote

Example
git push origin --tags

Config

git config --global user.name "[name]"

Set global username

Example
git config --global user.name "John Doe"
git config --global user.email "[email]"

Set global email

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

List all configuration

git config --global --edit

Edit global config file

What is Git Memo?

Git Memo is an interactive Git command reference and cheatsheet that provides quick access to essential Git commands. Whether you're a developer learning Git, a team lead managing repositories, or an experienced engineer needing a quick reference, our memo provides categorized commands with descriptions and examples.

This tool organizes Git commands by category including basic operations, branching, merging, remote repositories, stashing, rebasing, and advanced operations. Search functionality helps you find specific commands instantly.

Why Use Git Memo?

Git has hundreds of commands with complex options that are difficult to memorize. Developers need quick access to correct command syntax, especially for less-frequently used operations like rebasing, cherry-picking, and submodule management. Manual searching through documentation wastes valuable development time.

Developers use this memo to quickly find correct command syntax, learn new Git operations, and avoid common mistakes. Team leads benefit from sharing standardized Git workflows and best practices with their teams.

The tool saves time by providing instant command lookup, includes practical examples for each command, and organizes commands by workflow rather than alphabetically. It's particularly valuable when working with branches, resolving merge conflicts, and managing remote repositories.

Common Use Cases

Learning Git: Reference commands while learning version control workflows.

Branch Management: Find commands for creating, merging, and deleting branches.

Conflict Resolution: Look up commands for resolving merge and rebase conflicts.

Remote Operations: Access commands for pushing, pulling, and managing remotes.

Advanced Operations: Reference complex commands like interactive rebase and cherry-pick.

How to Use Git Memo

Using Git Memo is straightforward: browse commands by category or use search to find specific operations, click on commands to see detailed descriptions and syntax, copy commands to clipboard with examples, and bookmark frequently used commands for quick access. The memo includes common use cases and best practices for each command.

All commands are organized logically and include practical examples that you can adapt to your workflow. The tool works entirely in your browser without requiring any installation.

Related Tools

Explore more tools to enhance your productivity