Skip to content

neerukulhari/GitCheatSheet

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Git Cheat Sheet

Components of Cassandra

Clone the existing repositoty

git clone <CLONE_URL>

# Example
git clone https://github.com/JinnaBalu/GitCheatSheet.git

Init the local git

git init

Local Changes

Changed files in your working repo
git status
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 <file_name>

# EXAMPLE
git log -p README.md
Commit hitory by user
git blame <file_name>

#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 <branch_name>

# Example
git checkout jinnabalu/testBranchName
Create a new branch
git checkout -b <brach_name>

# Example
git checkout -b jinnabalu/myNewBranchName
Delete local branch
git branch -d <branch_name>

# Example
git branch -d jinnabalu/myNewBranchName

## Force delete if not merged
git branch -D jinnabalu/myNewBranchName
Delete remote/origin branch
git push origin --delete <branch_name>

# 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 <branch_name>

# Example
git push -u origin jinnabalu/myNewBranchName

GIT MERGE

Merging changes from feature_branch to develop

  1. 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

  1. Merge feature_branch to develop
git checkout develop 

git merge --no-ff origin feature_branch 

GIT RESET

  1. Soft Reset
git reset <commit_hash> --soft
  1. Mixed Reset
git reset <commit_hash>

#OR

git reset <commit_hash> --mixed
  1. Hard Reset
git reset <commit_hash> --hard

GIT REVERT

revert: inverse the changes from history and create a new commit

git revert <commit-hash>

GIT REBASE

rebase: re-write history commits in a different place

git rebase <commit-hash>

Git for Project Lead/Manager

  1. Get count of branches
git branch -a | wc -l
  1. Get the commits from individual
git shortlog -s -n --all

#OR

git shortlog -s -n
  1. 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 <BRANCH_NAME>
  1. List of branches
git branch -a

About

Git Cheat Sheet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 100.0%