Git commands: A quick overview

How to Use Git Commands to Configure and Make Your Git Life Easier

Git commands: A quick overview

This is a short introductory article for git commands.

Setup and Initialization

This command is used to initialize an existing folder as a git repo

git init


This is used to copy a git repo

git clone [URL]



Stage and Snapshot

Show modified files in the working directory that are staged for your next commit git status

Add a file for your next commit

git add [fileName]

to add all files

git add .


unstaged a file while retaining the changes in the working directory

git reset [fileName]


check the difference between what is changed but not staged

git diff

check the difference between what is staged but not yet committed

git diff --staged


Commit staged content as a new commit snapshot

git commit -m "message"



Branch and Merge

List your branches. A * will appear next to the currently active branch

git branch


Create a new branch at the current commit

git branch [branch-name]


Switch to another branch and check it into your working directory

git checkout


merge the specified branch's history into the current one

git merge [branch]


show all the commits in the current branch's history

git log



Inspect and Compare

show the commits on BranchA that are not in BranchB

git log branchB..branchA


show the commit that changed file, even across renames

git log --follow [file]


show the diff of what is in BranchA that is not in BranchB

git diff branchB..branchA

show any object in Git in human readable format

git show [SHA]



Tracking Path Changes

Delete the files from project and stage the removal for commit

git rm [file]


change an existing file path and stage the move

git mv[existing-path][new-path]


show all commit logs with indication of any paths that moved

git log --state -M



Share and Update

add a git URL as an alias

git remote add [alias][URL]


fetch down all the branches from that git remote

git fetch [alias]


Merge a remote branch into your current branch to bring it up to date

git merge [alias]/[branch]


Transmit local branch commits to the remove repo branch

git push [alias][branch]


fetch and merge any commits from the tracking remote branch

git pull



Rewrite History

apply any commits of current branch ahead of specified one

git rebase [branch]


clear staging area, rewrite working tree from specified commit

git reset --hard[commit]



Temporary Commits

Save modified and staged changes

git stash


list the stack-order of stashed file changes

git stash list


write working from top of stash stack

git stash stop


discard the changes from the top of stash stack

git stash drop


This is pretty much all important git commands. I hope it helped. Thanks and Keep Learning!

Did you find this article valuable?

Support Ashish Kr Jha by becoming a sponsor. Any amount is appreciated!