Git Commands: A Quick Reference Guide

This article reflects my current understanding as part of my professional learning journey. While I strive for accuracy, the content may be updated as my expertise deepens.

📝 Published: 07 May 2023 | 🔄 Updated: 02 May 2025 | ✍️ By

Show unstaged file differences to review changes.

git diff

Commit all tracked file changes with a message.

git commit -a -m "commit message"

View the current status of working directory and staging area.

git status

Stage specific file(s) to include in the next commit.

git add file_path

Create and switch to a new branch for development.

git checkout -b branch_name

Switch to an existing branch in your repository.

git checkout branch_name

Amend the previous commit without creating a new one.

git commit --amend

Push local branch updates to a remote repository.

git push origin branch_name

Fetch changes from remote and merge with local branch.

git pull

Interactively rebase commits to edit or squash history.

git rebase -i

Clone a remote repository to create a local copy.

git clone

Merge changes from one branch into another branch.

git merge

View commit logs along with file change statistics.

git log --stat

Temporarily stash uncommitted changes for later use.

git stash

Apply and remove the latest stashed changes.

git stash pop

Show detailed information about a specific commit.

git show commit_id

Undo the last commit but keep local changes intact.

git reset HEAD~1

Create a patch file for a specific commit’s changes.

git format-patch -1 commit_id

Apply changes from a saved patch file to the repo.

git apply patch_file_name

Force delete a local branch that is no longer needed.

git branch -D branch_name

Move branch reference to undo commits without loss.

git reset

Create a new commit to reverse changes from an earlier commit.

git revert

Apply a specific commit’s changes onto the current branch.

git cherry-pick commit_id

List all branches in the local repository.

git branch

Reset branch to specific commit, discarding all changes.

git reset --hard