Skip to content
Toolcroft

Developer Tools

Git Command Builder & Reference

Browse and search common Git commands organized by category. View descriptions, options, and copy commands ready to use in your terminal.

Setup

git init

Initialize a new local repository

git clone <url>

Clone a repository from a remote URL

git config --global user.name "<name>"

Set global username

git config --global user.email "<email>"

Set global email

Stage & Snapshot

git status

Show the working tree status

git add <file>

Stage a specific file

Flags: -A (all) · -p (patch/interactive)

git add .

Stage all changes in the current directory

git commit -m "<message>"

Commit staged changes with a message

Flags: --amend (amend last commit) · -a (auto-stage tracked)

git diff

Show unstaged changes

Flags: --staged (show staged diff) · --stat (summary)

git stash

Stash current working changes

Flags: pop (restore latest) · list · drop

Branching

git branch

List local branches

Flags: -a (all) · -d <branch> (delete)

git branch <name>

Create a new branch

git checkout <branch>

Switch to a branch

Flags: -b <branch> (create and switch)

git switch <branch>

Modern way to switch branches

Flags: -c <branch> (create and switch)

git merge <branch>

Merge a branch into the current branch

Flags: --no-ff (no fast-forward) · --squash

git rebase <branch>

Rebase current branch onto another

Flags: -i HEAD~N (interactive) · --abort · --continue

Remote

git remote -v

List remote connections

git remote add <name> <url>

Add a new remote

git fetch <remote>

Fetch from remote without merging

Flags: --all (all remotes) · --prune

git pull

Fetch and merge from tracking remote

Flags: --rebase (rebase instead of merge)

git push <remote> <branch>

Push commits to remote

Flags: -u origin <branch> (set upstream) · --force-with-lease · --tags

History

git log

Show commit history

Flags: --oneline · --graph --all · -p (show diffs) · -n <N> (limit)

git log --oneline --graph --all

Visual branch graph

git show <commit>

Show details of a specific commit

git blame <file>

Show who changed each line in a file

Undo

git reset HEAD <file>

Unstage a file

git checkout -- <file>

Discard working directory changes in a file

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 a commit

Tags

git tag

List tags

git tag <name>

Create a lightweight tag

git tag -a <name> -m "<message>"

Create an annotated tag

git push origin --tags

Push all tags to remote

Git command reference

CommandDescription
git initInitialize a new local repository
git clone <url>Clone a remote repository locally
git statusShow working tree status
git add .Stage all changes
git commit -m "<msg>"Commit staged changes with a message
git pullFetch and merge remote changes
git pushPush local commits to remote
git branch <name>Create a new branch
git checkout -b <name>Create and switch to a new branch
git merge <branch>Merge a branch into the current branch
git log --onelineCompact commit history
git stashSave uncommitted changes temporarily
git rebase -i HEAD~NInteractive rebase last N commits

How Git commands move your changes

  • Working directory: the files you see and edit in your project folder.
  • Staging area (index): where you assemble your next commit. git add moves changes here.
  • Repository: permanent history in .git/. git commit moves staged changes here.
  • Remote: a copy hosted elsewhere (GitHub, GitLab). git push uploads; git pull downloads and merges.

Branching strategies

  • Git Flow: long-lived main and develop branches with feature, release, and hotfix branches. Suited for versioned software with scheduled releases.
  • GitHub Flow: single main branch; feature branches merge via pull request and deploy immediately. Suited for continuously deployed web apps.
  • Trunk-Based Development: everyone commits to a single trunk using short-lived branches or direct commits with feature flags. Enables the highest deployment frequency.

Danger zone commands

These commands rewrite history or destroy work permanently:

  • git push --force: overwrites remote history. Anyone who already pulled will have a diverged history. Never force-push to main.
  • git reset --hard HEAD~n: discards commits and all working directory changes. Check git reflog within 30 days to recover.
  • git clean -fd: permanently deletes all untracked files and directories with no undo.