Git Cheat Sheet
Clone the existing repositoty
git clone
# Example
git clone https://github.com/JinnaBalu/GitCheatSheet.git
Init the local git
git init
Local Changes
Changed files in your working repo or Chnages in tracked files
git status
Add all current changes
git add --all
OR
git add .
commit all local changes in tracked files
git commit -am "my commit message"
a- all
m- message
Commit History
Show all commits, starting with the newest
git log
Commit history of specific file
git log -p
# EXAMPLE
git log -p README.md
Commit hitory by user
git blame
#Example
git blame README.md
Branches
List all local brnahces
git branch
List all local and remote brnahces
git branch -av
Switch to existing branch
git checkout
# Example
git checkout jinnabalu/testBranchName
Create a new branch
git checkout -b
# Example
git checkout -b jinnabalu/myNewBranchName
Delete local branch
git branch -d
# Example
git branch -d jinnabalu/myNewBranchName
## Force delete if not merged
git branch -D jinnabalu/myNewBranchName
Delete remote/origin branch
git push origin --delete
# Example
git push origin --delete jinnabalu/myNewBranchName
Pull and Push
Get latest from remote
pull: gets latest pushed by someone to the branch
git pull
Push local changes
push: push local cahnges to the remote branch
git push -u origin
# Example
git push -u origin jinnabalu/myNewBranchName
GIT MERGE
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
Git for Project Lead/Manager
Get count of branches
git branch -a | wc -l
Get the commits from individual
git shortlog -s -n --all
#OR
git shortlog -s -n
Get count the commits for the branch we are in
git rev-list --count HEAD
#OR
git log --pretty=oneline | wc -l
#OR
git rev-list --count
List of branches
git branch -a