Problem Git ? Install git Setup Git Github ? Life Cycle git Easy Life Cycle git Push to github All commands

Problem and Solution!


Hey Bob can you solve my problem ?

Ofcourse Uzi... What it is ?

// do this. solution This is the code you need...

hey it like my previous code...

show me the code you wrote !!

give me one minute...

Oh noo.. Ctrl+Z not working what should i do !

why don't you use any Version control system Like Git.

What is Git ?


Hey what is this Git ?

Git is a free and open source distributed version control system. And a version control system is responsible for keeping record of any change in you document you made. Like your solution Git would have all your Previous versions of your solution.

hey thats Cool. How to Install and, use Git ?

How to install Git ?


Installing git is very Easy task You can follow this Git_Download Link. And download for you own Operating System. And after installing Git not forget to Check in Command Prompt/ Terminal
git --version that will tell you the version of git which is install in your system. like
"git version 2.35.1.windows.2"

Hey you are Good Bro..👍

Hey if you are using ubuntu then you can install git in flash by just a command
sudo apt install git

How to setup Git.


hey I have done installing how to use Now ?

Now you need to make a new Directory at your favorite Location on your computer. Manually or with command
mkdir "name of dir"

Now goto your command line and open same directory that you have make or goto the directory and open command prompt/ terminal and type command in terminal/command-prompt
" git init " It will initialise Git in that Directory and Now git can keep record of your all edits 👀.

The first time you need to config global user-name and user-email by following command :-
git config --global user.name "yourUserName"
git config --global user.email "yourEmail"

After setting you can also get back userName and userEmail by this following command :-
git config --global user.name
git config --global user.email

Introduction to Github.


now i going to tell you about github.
Github is also a VCS but an online VCS however git is local vcs so you and your computer know all the changes. In order to kepp our file safe we need a online reposetry and Github provides that so now...

So now go to this link Github.com Make a account.

now login to github and go to create repository and give a name and hit create button.
now you have created a empty repository.

okay allright everything you say my friend!

Life cycle of Git.


Now in that directory you have initialised git files have 4 stage of state. In simple words :-
1. Untracked --: if you are creating a new file then that file is untracked.


example
touch new.txt
// this file is untacked.

2. Staged Files --: when you are wanted to save all change in file / files , you need to stage them or move to cart ( like Flipkart or amazon shoping cart 🛒 )


example
git status
it will tell you
Untracked files: (use "git add ..." to include in what will be committed)
new.txt

git add "new.txt" or git add . all untacked or modified file

3. Unmodified Files --: after staging / ading a file for confirm change you need to commit that file it ensures saving of all changes.


example
git commit -m "i have created a file"
it commit all changes with a message "message."


4. Modified Files --: after commiting a file if you make a change again it become modified and its stage is like 1st stage but git know this file so it is not untracked file. In order to save all changeg again you need to do step 2 and 3 again.


example
change new.txt
then do these command
git status
it will tell you Like
(use "git add ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) modified: new.txt
git add .
git commit -m "new changes made"

this will ensure all changes and we can also revert back to previous version by command
git restore "filename".

Easy way L.c.o.G command


Can you tell me all the commands.

not to worry anything, I will tell you


git status
git add . or git add "filename"
git commit -m "message"

Thats a relif. Thanks Bob.

Okay, Now we can move to pushing it online on github.

you are Great. bro...

Pushing to Github


for pushing online you need a online repository and if you remember we had created repository while back in this conversation. So go and copy its link from your github profile and use command.
for one time for one reposetry in one Directory


git remote add origion "link of online reposetry"

👉 For the first time you need to verify your account by browser or anything

git branch -M main

you can make "main" as your default branch

git push -u origin main main is branch name.

Every Day Commands


Okay so now tell me, how to keep my all versions of solution

This is pretty simple Uzi.
if change your code anytime just see in Your editor like Vs code or type a command..
git status
It will tell you if any modified or untracked file is present then
git add .
git commit -m "message"
git push -u origin main


example
git status
git add .
git commit -m "message"
git push -u origin main