getting started with git

21
Before and After Without version control system Project Directory bytes bytes Project Directory bytes bytes Project Directory bytes bytes bytes Day 1 Day 2 Day 3 Project Directory bytes bytes Project Directory bytes bytes Project Directory bytes bytes bytes Day 1 Day 2 Day 3 With version control system

Upload: pratz0909

Post on 19-Jul-2015

266 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Getting started with GIT

Before and AfterWithout version control system

ProjectDirectory

bytes

bytes

ProjectDirectory

bytes

bytes

ProjectDirectory

bytes

bytes

bytes

Day 1 Day 2 Day 3

ProjectDirectory

bytes

bytes

ProjectDirectory

bytes

bytes

ProjectDirectory

bytes

bytes

bytes

Day 1 Day 2 Day 3

With version control system

Page 2: Getting started with GIT

High level structure

Centralized

CentralRepository

TeamLead

Sr.Dev

Sr.Dev

Jr.Dev

Jr.Dev

Jr.Dev

Jr.Dev

Distributed

TeamLead

Sr.Dev

Jr.DevJr.Dev

Sr.Dev

Jr.DevJr.Dev

Page 3: Getting started with GIT

Features

Distributed development.

Every Developer has full copy.

Most operation are local, so its fast.

Strong support for non-linear development.

Page 4: Getting started with GIT

Create repository

$ git init

MyProjectrepo

Repository created

Page 5: Getting started with GIT

Clone a repository

$ git clone <url>

Local repo

Cloning complete repository to local

Remoterepo

Page 6: Getting started with GIT

Adding files/directories (modified)

$ git add <file/dir name>

Stagingarea

Workingdirectory

stage files

Page 7: Getting started with GIT

Committing changes

$ git commit -am “<commit message>”

Local repo

Stagingarea

commits

Why commit is important :

Each commit gets an SHA1

hash key.

What you put in is what

you get out.

Page 8: Getting started with GIT

Reset changes

$ git reset$ git reset --hard

Local repo

Stagingarea

Workingdirectory

Add – for modifiedOr new files

Remove for stagingarea

Page 9: Getting started with GIT

Key points

Git add :

– To add new files.

– To add files to staging area (shortcut: commit -a).

Git reset :

– Clear staging area.

– Clear local changes with “--hard” option.

Page 10: Getting started with GIT

Status of untracked/modified files

$ git status

Local repo

Stagingarea

Workingdirectory

stage files

commits

Page 11: Getting started with GIT

Remote repository

$ git remote add <repo_name> <url>

Local repo

Copy url name only

Remoterepo

Page 12: Getting started with GIT

Key points

Git clone :

– Creates a new repository by copying everything from an

existing repository.

Git remote add :

– Creates an entry with the name of a particular url in git

config file.

Page 13: Getting started with GIT

Pushing changes

$ git push <repo_name> <branch_name>

Local repo

Stagingarea

Workingdirectory

Remote repo

Push changes

Page 14: Getting started with GIT

Pulling changes

$ git pull <repo_name> <branch_name>

Local repo

Stagingarea

Workingdirectory

Remote repo

Pull changes

Page 15: Getting started with GIT

Fetching changes

$ git fetch <repo_name> <branch_name>$ git rebase <repo_name>/<branch_name>

Local repo

Stagingarea

Workingdirectory

Remote repo

Fetch changes

Rebase

Page 16: Getting started with GIT

Key points

Git pull :

– Internally it is 'git fetch' + 'git merge'.

Git fetch :

– Gets all the changes but does not apply to working copy.

Git rebase :

– Changes the commit history to match remote repo and applies

changes to working copy.

There are two ways to integrate changes 'merge' and 'rebase'

respectively.

Page 17: Getting started with GIT

Create branch

$ git branch <branch_name>

Master

B1

You are here

Page 18: Getting started with GIT

Switch between branch

$ git checkout <branch_name>

Master

B1

You are here

B2

Page 19: Getting started with GIT

Merge branch

$ git merge <branch_name>

Master

B1 You are here

Page 20: Getting started with GIT

Tagging

$ git tag <commit hash key>

Master

Tagged a commit

Page 21: Getting started with GIT

Powered by

Prathamesh Nevagi