Skip to main content

Command Palette

Search for a command to run...

Git : Basic And Essential Commands

Published
•4 min read•View as Markdown

What is Git

Git is a version control system .

in easy words :- Git tracks the changes in our code (file) so we don’t lose the code and go back to older version anytime.

on Git many programmers can work together without overwriting each other works.

Why Git is used

git helps programmers save , track , and manage code safely.

  1. To save your work

  • What you changed

  • when you changed

  • why you changed

so even if you delete something by mistake —> Git can restore it

  1. To work without fear

  • Experiment with code without fear

  • Even try new ideas and concepts

  1. To work with a team

    Many people can work on same project.

For example:-

  • One person design the website(htma & css)

  • otherone do the backend (how the icons or buttons work ).

  1. To track progress

Git shows :-

  • Who changed the code.

  • What was changed.

  • When it changed.

very useful in real projects.

Git basics and core terminologies

core git concepts

These are the heart of git.(repository , commit , branch , head )

Repository(Repo)

repository is folder where:-

  • Your project file live.

  • Git tracks all changes.

  • History is stored.

Types:-

  • Local repository —> On your computer

  • Remote repository —> On git server

example :- School bag

  • books=files

  • notes history (like date section) :- git tracking.

Commit

A commit is a saved snapshot of your project .

“According to git :- I will remember your project exactly like this”

Each commit has :-

  • Unique ID (hash)

  • Message (what you changed)

Branch

A branch is a separate line of development.

  • Try new features.

  • fix bugs

  • experiment safely

Example :- Roads from a highway

  • Main road = main branch

  • side road = side branch

  • join back later = merge

Head

Head is like a pointer that tells “ Where are you right now in git”.

head points to The latest commit of the current branch.

Example :- pointer on a map which shows current location.

Simple diagram

commit A —> commit B —> commit C <—-Head

head is on commit c.

Git termReal life
RepositoryNotebook
CommitPage saved
BranchExtra rough notebook
HeadBookmark

Cmman git command

git init , git status , git add , git commit , git log, git branch , git switch ,git merge , git push , git pull

  1. git init

    Turns normal folder to git repository.

When to use:- Starting a new project.

  1. git status

shows the current status of project.

It tells

  • Which file changed

  • Which are staged

  • which are not tracked

  1. git add

save the changes in files

  1. git commit

saved a snapshot of changes

git commit -m

  1. git log

shows commit history

you see :-

  • Commit ID

  • Author

  • Date

  • Mesaage

  1. git branch

    shows , creates or deletes branches

show branches :- git branch

create new branches:- git branch feature- login

  1. git switch

    moves to another branch

    ex:- git switch feature- login

Head moves to that branch

  1. git merge

combine one branch to another

ex:- git merge feature- login

  1. git remote

    connect local repo to git server

    ex:- git remote add original URL

  2. git push

    sends commits to git server.

    ex:- git push main server

  3. git pull

    downloads latest changes from git server

    ex:- git pull main server

  4. git clone

    copies existing repository from git server.

    ex:- git clone URL

Summary

Commandmeaning
git initstart git
git statuscheck changes
git addstage changes
git commitsave snapshot
git branchmanage branches
git switchchange branches
git mergecombine branches
git pushupload
git pullDownload
git cloneCopy repo