git
DESCRIPTION
This presentation is about how to use Git, the distributed version control system. It helps you to get started with Git and explains the basic concepts.TRANSCRIPT
![Page 1: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/1.jpg)
GitThe fast version control system
![Page 2: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/2.jpg)
Version Control System
• Allows to track changes to files
• Provides repository of changes
• Consists working directory / current state
• VCS can be:• Centralized (Ex: SVN, CVS)
• Server: single database• Clent: working directory and state.
• Decentralized(Ex: BitKeeper, Mercurial, Git)
![Page 3: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/3.jpg)
What is Git?
• free & open source
• distributed version control system • Anyone can be the server• Repository coupled with working directory• Complete history• Disconnected operation• No single point of failure
• Designed to be fast and efficient for small and very large size projects
![Page 4: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/4.jpg)
Git history
• 2002• Linus Torvalds decided to use BitKeeper for
tracking Linux kernel development• Linux development scales better
• 2005• BitMover dropped free license• Linus writes his own VCS, Git
![Page 5: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/5.jpg)
Getting started with Git
• yum install git-core
• git clone --help
• git config --global user.name ‘Keshavaprasad B S’
• git config --global user.email [email protected]
![Page 6: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/6.jpg)
Getting started with Git
• Creating new git repo:• git init
• git add
• git commit
• Cloning from existing repo:• man git-clone
![Page 7: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/7.jpg)
Git config
• Types• $(prefix)/etc/gitconfig --> system• ~/.gitconfig --> global• .git/config --> local
• Aliases
![Page 8: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/8.jpg)
Concept of working directory, index and repository
• git add -> adds stuff to index
• git commit -> commits stuff from index to repository
• git diff -> diff between working tree and index
• git diff --cached -> diff between HEAD and repository
![Page 9: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/9.jpg)
Concept of working directory, index and repository
• git fetch-> fetch the code from remote repo to local
• git pull -> pulls code from remote to local and w.d.
• git checkout -> checkout code from local repo to w.d.
![Page 10: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/10.jpg)
Git object model
• All the information needed to represent the history of a project is stored in files referenced by a 40-digit SHA1 hash.
• Each object consists of type, size and contents.
• 4 types of objects• Blob – stores files data (generally a file)• Tree – consists bunch of other trees or blobs (files
and subdirectories)• Commit – points to a single tree. Contains meta of
author, timestamp, pointer to prev. commit etc.• Tag – Marks a specific commit
![Page 11: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/11.jpg)
Git object model
• Git show <sha>
![Page 12: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/12.jpg)
gitk and git log
• Install gitk
• git log --pretty=oneline
• git log --pretty=format:'%h : %s' --topo-order –graph
• git log --no-merges
• git log --stat
![Page 13: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/13.jpg)
Git branches
• git clone [email protected]:kbsbng/try_git.git
• git branch hack-1
• Make changes and commit to branch and master
• git rebase master hack-1
• git merge hack-1
![Page 14: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/14.jpg)
Git merge/rebase
1. git checkout -b mywork origin
3a. git pull
3b. git pull --rebase
![Page 15: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/15.jpg)
Git tags
• Lighweight tags (branch that never moves)• git tag stable-1 <commit>
• Tag Objects• Can include comments / signature• git tag –a stable-1 <commit>
![Page 16: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/16.jpg)
Stashes
• git stash save “WIP for foo feature”
• git stash apply
• git stash list
![Page 17: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/17.jpg)
Some tips
• Git grep can be used search through previous versions of a project without checking them out.
• master@{yesterday} refers to where the master branch was yesterday.
![Page 18: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/18.jpg)
Git vs svn
• Cheap local branching
• Everything is Local
• Fast
• Git is small
• Provides staging area
• Distributed
• Any workflow
• Github
![Page 19: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/19.jpg)
References
• http://book.git-scm.com/
• http://whygitisbetterthanx.com
![Page 20: Git](https://reader035.vdocument.in/reader035/viewer/2022081518/54b7830d4a7959a8698b4617/html5/thumbnails/20.jpg)
Thank you