GIT Presentation

34
GIT the stupid content tracker Resources: Peep Code and Git-SCM

description

A Presentation on GIT SCM Tool. Covers Basics and Internals of GIT Few References [Recommended Learning]: http://git-scm.com/doc https://github.com/pluralsight/git-internals-pdf/releases Few Interactive Learning [Will get you going]: https://try.github.io/levels/1/challenges/1 http://pcottle.github.io/learnGitBranching/

Transcript of GIT Presentation

Page 1: GIT Presentation

GITthe stupid content tracker

Resources: Peep Code and Git-SCM

Page 2: GIT Presentation

GIT“In many ways you can just see git as a filesystem — it’s content-addressable, and it has a notion of versioning, but I really really designed it coming at the problem from the viewpoint of a filesystem person (hey, kernels is what I do), and I actually have absolutely zero interest in creating a traditional SCM system.” – Linus

GIT as a SCM is an usecase

Non-SCM Use Cases of GIT:

Peer to Peer Content Distribution Network

Distributed Document Oriented Database [like wiki]

Page 3: GIT Presentation

GIT 1. Non Linear Development - Cheap and efficient branching2. Distributed Development - No repository is special3. Efficiency - Fastness, Size & Network Operations

Page 4: GIT Presentation

The GIT Way1. Snapshots not differences

2. Nearly every operations are local.

3. Ensures Integrity.

4. Undo is always an option.

5. And the three states

Page 5: GIT Presentation

GIT Setup1. Setting up the origin2. Setting up the local

Page 6: GIT Presentation

GIT Tracking

Page 7: GIT Presentation

GIT Tracking1. Staging2. Status3. Viewing the diff

3.1 Working directory and Stage3.2 Stage and a Commit3.3 Working directory and a Commit

4. Remove5. Move or Rename6. Referencing

Page 8: GIT Presentation

GIT Tracking1. Commit2. Undo

2.1 Checkout

2.2 Reset [hard, soft, mixed - default]2.3 Revert

3. Working with remote

An interactive Demo

Page 9: GIT Presentation

GIT TrackingIgnores Files from1. .gitignore from directories [like IDE Related Folders]2. $GIT_DIR/info/exclude [Project Specific Setting like logs, binaries]3. core.excludesfile [Stuffs needn’t be shared among developers]

Page 10: GIT Presentation

GIT Tracking (Checkout vs Reset vs Revert)

Page 11: GIT Presentation

GIT Objects1. Blob2. Tree3. Commit4. Tag

*3 in italics are important to understand git

Page 12: GIT Presentation

GIT Objects1. The Git Directory serves as the Git Object Database.2. Each object is compressed and referenced by SHA-1 value of [Header + Content].

Page 13: GIT Presentation

GIT Objectstamil@dv-lp-tamil-s:~/gitdemo$ git initInitialized empty Git repository in /home/tamil/gitdemo/.git/tamil@dv-lp-tamil-s:~/gitdemo$ cd .git/tamil@dv-lp-tamil-s:~/gitdemo/.git$ lltotal 40drwxr-xr-x 7 tamil tamil 4096 Mar 24 17:25 ./drwxr-xr-x 3 tamil tamil 4096 Mar 24 17:25 ../drwxr-xr-x 2 tamil tamil 4096 Mar 24 17:25 branches/-rw-r--r-- 1 tamil tamil 92 Mar 24 17:25 config-rw-r--r-- 1 tamil tamil 73 Mar 24 17:25 description-rw-r--r-- 1 tamil tamil 23 Mar 24 17:25 HEADdrwxr-xr-x 2 tamil tamil 4096 Mar 24 17:25 hooks/drwxr-xr-x 2 tamil tamil 4096 Mar 24 17:25 info/drwxr-xr-x 4 tamil tamil 4096 Mar 24 17:25 objects/drwxr-xr-x 4 tamil tamil 4096 Mar 24 17:25 refs/

Page 14: GIT Presentation

GIT Objects [blob]1. Stores Contents of files.2. No file metadata.3. Two different files with similar contents are marked one [even while transfers].

Page 15: GIT Presentation

GIT Objects [tree]1. List of trees and blobs [similar to ls -l in unix] + Some Header.2. An entry in tree has mode, type, name and sha of file or another tree.

Page 16: GIT Presentation

GIT Objects [commit]1. Holds a reference to a tree object.2. Has author, committer, message and any parent commits that directly preceded it.3. History is built from the references to parent commits.

Page 17: GIT Presentation

GIT Objects [tag]1. Refers to one particular commit object.2. Has object, type, tag, tagger and a message.3. Mostly the type is commit and object referred is the SHA-1 of commit being tagged.

Page 18: GIT Presentation

GIT Data Model

commit

tree

blob

HEAD

branch

remote tag

Page 19: GIT Presentation

GIT Data Model [Demo]

…. Some Action

Page 20: GIT Presentation

Branching and Merging1. Creating a branch is nothing more than just writing 40 characters to a file.2. Add Remotes to point to other people copies.

Merge Types:Fast Forward [--no-ff]3-Way Merge

Merge Strategies:Resolve

Recursive [Default for merging 2 branches]

Ours

Octopus [Default for merging from more than one branch]

Subtree

Page 21: GIT Presentation

Merging [Fast Forward]

After Merge:

C0 C1 C3

Test

HEAD

C0 C1 C3

HEAD

Test

C0 C1

C3

HEAD

Test

C4

--no-ff Mode:

Page 22: GIT Presentation

Merging [3-Way]

C0 C1 C3

C4

HEAD

Test

C0 C1 C3

C4

Test

C5

HEADBase Ours

Theirs

Page 23: GIT Presentation

More Complex Merges

Page 24: GIT Presentation

More Complex Merge [contd.]

Page 25: GIT Presentation

GIT Tagging1. Lightweight - Just a cheap reference to a commit2. Annotated - More than a reference

Tags can be published or shared with other developers via push.They aren’t pushed by default.

git-describe - Shows the most recent tag that is reachable from a commit

Page 26: GIT Presentation

GIT Stash1. Helps switching to a different branch even when working directory isn’t clean.2. Saves uncommitted changes [modified tracked files and staged changes] as WIP in master.

3. Can be reapplied, dropped or applied on a new branch.

Page 27: GIT Presentation

GIT Patches & Cherry Picks1. Patches are alternate for merge or pull requests [SVN way].2. Can Merge specific file from different branch or a commit using patch mode.3. Cherry Pick helps in applying specific commit from same or another branch.

Page 28: GIT Presentation

GIT GrepFile Grep:git grep -e “isStringSet” *.js

Log Grep:git log --grep=fix --author=tamil.s since=’yesterday’

Page 29: GIT Presentation

GIT LogList By (with stats or patches):UserTime Limit [before, after, since and until]GrepLocate the introductory Commitand many more..

Might take an year to explore ;)

Page 30: GIT Presentation

GIT Workflows

Centralized Workflow

Page 31: GIT Presentation

GIT Workflows

Integration manager

Page 32: GIT Presentation

GIT Workflows

Benevolent Dictator

Page 33: GIT Presentation

GIT Lab1. Managing your profile2. Creating a project3. Managing Members4. Code Reviews & Comments5. Managing Issues + Milestones6. Cool Commit Messages7. Merge Requests

Page 34: GIT Presentation

Questions