Skip to main content

Command Palette

Search for a command to run...

What is Git and How Does It Work?

Published
3 min readView as Markdown

what is git

Git is the version control system which keeps the track of the changes which you have made in the present file from previous file (but when you initiated it )


Why Git is used

Git is used for the convenience Purpose to track - the change which has been made by different person working on the same project (or in simple word changes made by whom ---->(Fancy word for whom ---collaborator) and when including what the change ).


Learn Git Basic

How to use git and what are the basic command in git

  • Step 1 ----> Please install the git and make a account on it

  • Step 2 ----> make a file with any Extension (recommended .txt)

git init

It initialize the git for our file so that it can make a file to keep the change (.git file)

C:\Users\ranja\Desktop\git demo> git init

**Output :——**Initialized empty Git repository in C:/Users/ranja/Desktop/git demo/.git

git status

This command of git show is there any changes from the previous commit which has made by you or collaborator which is added for commit.

C:\Users\ranja\Desktop\git demo> git status

**Output :——**No commits yet Changes to be committed: (use "git rm --cached ..." to unstage) new file: page1.txt new file: page2.txt

git add

  • git add <file name>

Add the file for commit on which you want to save the change in (term Staging area)

C:\Users\ranja\Desktop\git demo> git add page2.txt
  • git add .

Add all the changes which you have made in the folder In different files of same folder 📁 for commit in (term Staging area)

C:\Users\ranja\Desktop\git demo> git add .

Output :—— [master 753ba4b] commit for page2 1 file changed, 1 insertion(+)

git commit

  • git commit <file name> - m “message”

it save the change along with message for the particular file which name is taken as (file name).

C:\Users\ranja\Desktop\git demo> git commit page2.txt -m "commit for page2"

git commit . - m “message”

It save all the files with single message that you have added for commit.

C:\Users\ranja\Desktop\git demo> git commit . -m "commit all at once"

Output :——[master 4ed24b1] commit all at once 1 file changed, 2 insertions(+), 2 deletions(-)

git log

  • git log

this log all the changes make till the last commit in the repo

C:\Users\ranja\Desktop\git demo> git log

Remember your terminal may get stuck to exist from this situation just click (q)

it means it opens the output in pager ( fancy name terminal is inside less)

  • git --no-pager log
 C:\Users\ranja\Desktop\git demo> git --no-pager log

git diff

  • git diff

Where (in which file) and what changes has made but not commited

C:\Users\ranja\Desktop\git demo>  git diff
  • git diff

it also give the different between <previous node hexacode> <next node hexacode>

C:\Users\ranja\Desktop\git demo>  git diff  0946f9291  753ba4b

git revert

  • git revert <hexacode of node where you want to go back>

It will remove the last change but you need to commit your changes( means you head node do not change yet)

C:\Users\ranja\Desktop\git demo> git revert 4dc2b6e2f6

Output :—— Please commit your changes or stash them before you merge.

git reset

  • git reset -- hard <hexacode till where you want to remove >

It will remove the all change till that node make the head pointing to that node so be careful as it remove every thing till there

C:\Users\ranja\Desktop\git demo> git reset --hard  753ba4ba3d

Output :—— HEAD is now at 753ba4b commit for page2

More from this blog

Learn With Ranjan

13 posts