My Brain Cells

Easiest (and best) learning materials for anyone with a curiosity for machine learning and artificial intelligence, Deep learning, Programming, and other fun life hacks.

All the “Commands” for Git you need to know


# first configure your credentials in your pc
git config --global []

#set automatic command line coloring for Git for easy reviewing
git config --global color.ui auto


git init

# to clone a repo
git clone

Stage & Snapshot:

# to show modified file in working directory
git status

# to add files
git add [file] or git add .

# to retain the changes
git reset [file]

# to see what is changed but not staged
git diff

# to see what is is stages but not committed
git diff --staged

# to commit 
git  commit -m "[message]"

Branches and Merges:

# to list the branches
git branch

# to create branch
git branch [branch-name]

# to switch to another branch and checkout
git checkout

# to merge to specific branch 
git merge [branch]

# to show all the commits in the current branch 
git log

Inspect & Compare:

git log

# to show commits on A that are not on B branch 
git log branchB..branchA

# to show commits that changed file
git log --follow [file]

# to show diff on A that are not on B
git diff branchB...branchA

# to show any object in human readable format
git show [SHA]


# to remove file for the project
git rm [file]

# to move the file
git mv [existing-path] [new-path]

#to show all commit logs with indication of any paths that moved
git log --stat -M

Share and Update:

# add git URL as an alias
git remote add [alias] [url]

# to fetch all the branches from that git remote
git fetch [alias]

# to merge remote branch into current branch
git merge [alias]/[branch]

# to transmit local brach commits to remote repo brach 
git push [alias] [brach]

# to fetch and merge any commits
git pull

Rewrite History:

# apply any commits to current brach ahead of specified one
git rebase [branch]

# to cleare staging area, rewrite working tree from spcified commit
git reset --hard [commit]

Temporary commits:

# save modified and staged changes
git stash

# list stack order of stashed files chanages
git stash list

# to write on top of stash stack 
git stash pop

# to discard the changes from top of stash stack
git stash drop

note: You can find a simple git tutorial here


Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top