You are on page 1of 4

Git

Git Installation:
we can install git in different environments like
1) Windows
2) Red hat (centos) or Linux
3) Mac
Windows Installation
install power shell latest version in windows machine. Right click on power shell
icon --> select run as administrator

go to https://chocolatey.org/install find and copy the following Command and paste it


into power shell window .
$ Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object
System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
and hit enter. It will install chocolatey in your local system. After install chocolatey
type following command for install Git in your local system

$ choco install git -y (-y will not ask any conformation)

once u hit enter command it start install Git in ur local system


Ubuntu or Centos Installation
Open terminal enter following commands
$ sudo apt-get update
$ sudo apt-get install git -y
$ sudo yum install git -y
Mac Installation
install homebrew or xcode
Start work on Git

Staging area / Local


Wowork area /
work Tree Index Area Repository

first we need create local repository (repository maintain versions\history info ).


For that open power shell create a directory \ Folder
$ mkdir dirname , $ cd dirname
$ mkdir learngit , $ cd learngit
now we are in learngit location. in this need to initialization of git
$ git init
this command create local repository( this repository maintain history of changes)
when we create local repository it internally creates or treats 3 logical areas
1. working area
2. staging area
3. local repository
start work in working tree(here we develop code or do changes) and add those
changes in staging area. Now go to git location through power shell create files
any where
$ touch 1.txt or New-Item 1.txt (type: file)
$ touch 2.txt or New-Item 2.txt (type: file)
we want to know what action performed previously. for that type below
command
$ git status
it will give some untracked files info.After changes done we need to add or move
those changes to staging area

Add changes from work tree to


staging area
work area / work Tree Staging area / Index Area
for that type command
$ git add 1.txt
$ git status
$ git add 2.txt
$ git status
after add changes to staging area we need to commit or save those changes in
local repository for maintain versions / History

commit changes from staging area to local


Stage area rep Local
Repository

if we want commit changes in local rep it requires 3 configuration details for first
time only

 User Name , Email , Message

for that we need to type commands to configure information


$ git config --global user.name "xxxxxxxxx"
$ git config --global user.email "mail@mail.com"
we need write message every time when we commit.now changes move from
stage to local rep
$ git commit -m " First commit "
to check history
$ git log
create two folders or directories
$ mkdir docs
$ mkdir test
after that in the test folder create a file
$ touch test\3.txt
$ sudo apt-get install tree -y
to know changes
$ git status
note: git never identifies empty directories / folders
Now add changes to staging area
$ git add test /
$ git status
move changes to local rep
$ git commit -m " second commit"
$ git status
$ git log

You might also like