git most used commands code example

Example 1: git commands

//initialize git
git init

//Connect with git live code
git remote add origin *Enter URL Here*

//Pull from origin main
git pull origin main

//Pull from origin master
git pull origin master

//To check status of changes
git status

//add all
git add .

//add fileA.css fileB.js
git add fileA.css fileB.js

//Commit changes
git commit -m "your commit on changes"

//Push to master
git push -u origin master

Example 2: Common GIt Commands

git init
//add all
git add .

//cancel adds
git reset

//cancel commits
git reset HEAD^
//cancel last 3 commits
git reset HEAD~3

//when first commit
git push -u origin master

//remove remote origin
git remote remove origin

//reset remote origin
git remote add origin https://github.com/yourname/project.git

Example 3: git basic commands

git fetch origin

git reset --hard origin/master

Example 4: git basic commands

git diff <sourcebranch> <targetbranch>