jinna.balu@outlook.com +91 98669 70525

Git Cheat Sheet


Clone the project from the repository



git clone git@github.com:JinnaBalu/jinnabalu.github.io.git

git clone https://github.com/JinnaBalu/jinnabalu.github.io.git


Initialize new local repository

git init

Get Latest
git pull

git pull origin [BRANCH_NAME]

Commit local changes

git add --all git commit -am "message"

Show commits history

git log

Show history of the file

git log -p [file]

Who changed what and when

git blame [file]

Branch Management

List All branches

git branch -av

Switch between Branches

git checkout [BRANCH_NAME]

Create a new branch

git checkout -b [BRANCH_NAME]

Delete Branch

git branch -d [BRANCH_NAME]

Forceful Delete

git branch -D [BRANCH_NAME]

Delete remote branch

git branch -dr [BRANCH_NAME]

Merge changes between branches

Merging changes from feature_branch to develop

Get latest from develop and merge to feature_branch

git checkout develop

git pull

git checkout feature_branch

git merge --no-ff origin develop

Note : To be safe from conflict with develop(GOOD PRACTICE), we will resolve in feature_branch

Merge feature_branch to develop

git checkout develop

git merge --no-ff origin feature_branch

Check the status of the local changes

git status

Check the status of lines changed

git diff


Listing remote

git remove -v

Switch remote URL between https - ssh

git remote set-url origin [https://[url]]

git remote set-url origin [git@git://[url]]

Discard all local changes

git reset --hard HEAD

Discard all local changes of file

git checkout HEAD [FILE_PATH]

Soft Reset

git reset [commit_hash] --soft

Mixed Reset

git reset [commit_hash] --mixed

git reset [commit_hash]

Hard Reset

git reset [commit_hash] --hard