Git Cheatsheet

Quick reference guide for essential Git commands. Searchable cheatsheet covering branches, commits, merges, and more.

Team Development Workflow

In professional environments, teams typically follow a branching strategy where each task gets its own branch. This isolates features and prevents unfinished code from breaking the main application.

💡

Professional Tips: Always strive for small, atomic commits. Before merging your work, use 'git fetch' then 'git rebase origin/dev' (or main) to ensure your code is compatible with the latest version. Finally, use 'git push -f' on your feature branch to update the remote with your rebased history.

Configuration

Set the global config

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

Configures your identity across all repositories on your system.

Get started

Create a git repository

git init

Initializes a new Git repository in the current directory.

Clone an existing git repository

git clone [url]

Copies an existing Git repository from a remote server.

Commit

Commit all tracked changes

git commit -am "[commit message]"

Stages and commits all modified tracked files in one command.

Add new modifications to the last commit

git commit --amend

Updates the last commit with current changes and optionally changes the message.

Branching

Create a new branch

git branch [branch-name]

Creates a new branch on the current pointer.

Switch to a branch

git checkout [branch-name]

Switches the HEAD to the specified branch.

Merge a branch into current branch

git merge [branch-name]

Combines history from another branch into your current one.

Create and switch to a branch

git checkout -b [branch-name]

The most common way to start working on a new feature.

Syncing

Fetch updates from remote

git fetch

Downloads remote changes without merging them.

Pull latest changes

git pull

Fetches changes and immediately attempts to merge them.

Rebase current branch on main

git rebase main

Replays your commits on top of the latest main branch.

Push changes (Force)

git push -f

Force updates the remote branch with your local history. Use only on private branches!

Useful Commands

Check status

git status

See which files are modified, staged, or untracked.

Stash changes

git stash

Temporarily hides changes to work on something else.

View history

git log --oneline --graph --all

Visualizes the commit history across all branches.

How to Use This Git Cheatsheet

  1. Browse the cheatsheet to find the Git command you need.
  2. Commands are organized by category: Configuration, Get Started, Commit, Branching, Syncing, and Useful Commands.
  3. Click the copy button next to any command to copy it to your clipboard.
  4. Paste the command into your terminal and modify the placeholder values as needed.

Advanced Rebasing

Rebasing is often preferred over merging to maintain a clean, linear project history. Instead of creating a 'merge commit', it repositions your commits at the end of the target branch.

Tip

Remember: Never rebase a public branch that others are working on, as it rewrites history and can cause significant conflicts for your peers.

Key Features

  • Essential Git commands organized by workflow category
  • One-click copy for every command
  • Clear descriptions explaining what each command does
  • Covers configuration, branching, syncing, and more
  • Team workflow guidance with professional tips
  • Rebasing best practices and safety warnings
  • Works offline once loaded in your browser

Common Use Cases

  • Quick reference while working in the terminal
  • Onboarding new developers to Git workflows
  • Reviewing branching and merging strategies
  • Learning Git commands for the first time
  • Refreshing memory on less frequently used commands
  • Setting up Git configuration on a new machine

Frequently Asked Questions

What is the difference between git merge and git rebase?

Git merge creates a new merge commit that combines two branches, preserving the full history. Git rebase replays your commits on top of the target branch, creating a linear history. Rebase produces a cleaner log but should never be used on shared public branches.

When should I use git stash?

Use git stash when you need to switch branches but have uncommitted changes you are not ready to commit. Stash saves your working directory state temporarily. You can restore it later with 'git stash pop' on any branch.

Is it safe to use git push --force?

Force pushing is safe only on branches that you alone work on, such as personal feature branches. Never force push to shared branches like main or develop, as it rewrites remote history and can cause other team members to lose their work.

Related Tools