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 initInitialize 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 statusShow 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 diffShow unstaged changes
Flags: --staged (show staged diff) · --stat (summary)
git stashStash current working changes
Flags: pop (restore latest) · list · drop
Branching
git branchList 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 -vList 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 pullFetch 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 logShow commit history
Flags: --oneline · --graph --all · -p (show diffs) · -n <N> (limit)
git log --oneline --graph --allVisual 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~1Undo last commit, keep changes staged
git reset --hard HEAD~1Undo last commit and discard changes
git revert <commit>Create a new commit that undoes a commit
Tags
git tagList tags
git tag <name>Create a lightweight tag
git tag -a <name> -m "<message>"Create an annotated tag
git push origin --tagsPush all tags to remote
Git command reference
| Command | Description |
|---|---|
git init | Initialize a new local repository |
git clone <url> | Clone a remote repository locally |
git status | Show working tree status |
git add . | Stage all changes |
git commit -m "<msg>" | Commit staged changes with a message |
git pull | Fetch and merge remote changes |
git push | Push 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 --oneline | Compact commit history |
git stash | Save uncommitted changes temporarily |
git rebase -i HEAD~N | Interactive 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 addmoves changes here. - Repository: permanent history in
.git/.git commitmoves staged changes here. - Remote: a copy hosted elsewhere (GitHub, GitLab).
git pushuploads;git pulldownloads and merges.
Branching strategies
- Git Flow: long-lived
mainanddevelopbranches with feature, release, and hotfix branches. Suited for versioned software with scheduled releases. - GitHub Flow: single
mainbranch; 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 tomain. -
git reset --hard HEAD~n: discards commits and all working directory changes. Checkgit reflogwithin 30 days to recover. -
git clean -fd: permanently deletes all untracked files and directories with no undo.