Skip to main content
imvinojanv.dev
  • About
  • Blog
  • Projects
  • Snippets

Command Palette

Search for a command to run...

imvinojanv.dev
Open to Hire

I'm always open to discussing software engineering work or partnership.

HomeAboutResumeUses
BlogProjectsSnippets
© 2026 Vinojan Veerapathirathasan —— Colombo, Sri Lanka.
MediumGitHubLinkedInRSS
Back

Git Cheat Sheet

Boost your Git proficiency effortlessly with this essential Git cheat sheet, designed to rescue you from command-related headaches.

Published on October 07, 2025
4 min read
0 views

Global Setup

User Information Configuration for Universal Application Across Local Repositories

git config --global user.name "[firstname lastname]"
# set a name globally to associate your name with your Git commits
git config --global user.email "[valid email]"
# set an email address that will be associated with each history maker
git config --global color.ui auto
# set automatic command line to improve the readability of Git's output by color-coding different types of information,
# such as branch names, status indicators, and more.

Initializing

Initializing and cloning repositories

git init
# initialize an existing directory as a Git repository
git clone [url]
# retrieve repository from a hosted location via url

Stage & Snapshot

Working with snapshots and Git staging area

git status
# show modified files in your working directory
git add [file]
# add a file to the staging area in Git. Use '.' to add all files
git reset [file]
# unstage a file from Git staging area
git diff
# display the differences (or "diffs") between the changes in working directory
# and the last committed version of the files in your Git repository
git diff --staged
# display the differences (or "diffs") between the changes that are staged (added to the Git staging area)
# and the last committed version of the files in your Git repository
git commit -m "[descriptive message]"
# create a new commit in Git with a descriptive message
# this command captures the changes that are currently staged and saves them as a new commit in the Git history

Branch & Merge

Isolating work in branches, and integrating changes

git branch
# list all local branches in the repository
git branch [branch-name]
# create a new branch
git branch -d [branch-name]
# delete a specific branch
git checkout [branch-name]
# switch to another branch
git checkout -b [branch-name]
# create a new branch and switch to it immediately
git merge [branch-name]
# merge changes from the specified branch into the current branch

Inspect & Compare

Analyzing logs and commits

git log
# display a chronological log of commits in a Git repository
git log --oneline --graph --all
# visualize history of all branches with a streamlined graph view
git show [commit]
# display the metadata and content changes of the specified commit
git reflog
# show a log of all references (commits, checkouts, etc.) to help recover lost commits

Share & Update

Retrieving updates from another repository and updating local repository

git remote add [alias] [url]
# add a remote repository to your Git configuration with a specified alias
git remote -v
# list all currently configured remote repositories
git fetch [alias]
# fetch updates from a remote repository explicitly
git push [remote] [branch]
# transmit local branch commits to the remote repository branch
git pull
# fetch and merge any commits from the tracking remote branch

Rewrite History

Rewriting branches, updating commits and clearing history

git rebase [branch]
# apply any commits of current branch ahead of specified one
git reset --hard [commit]
# clear staging area, rewrite working tree from specified commit
git commit --amend
# modify the most recent commit (change message or add forgotten files)
git commit --amend --no-edit
# modify the most recent commit without changing the commit message
git revert [commit]
# create a new commit that undoes all changes from the specified commit

Temporary Commits

Temporarily store modified, tracked files in order to change branches

git stash
# temporarily save changes in your working directory that are not yet committed
git stash list
# show a list of stashes that you've created in your Git repository
git stash pop
# apply the most recent stash and remove it from the stash list
git stash drop
# remove the most recent stash from the stash list
0
0
0
0
0