• Save
Git tech talk
Upcoming SlideShare
Loading in...5
×
 

Git tech talk

on

  • 719 views

 

Statistics

Views

Total Views
719
Views on SlideShare
654
Embed Views
65

Actions

Likes
0
Downloads
0
Comments
0

4 Embeds 65

http://blog.razasayed.com 27
http://www.razasayed.com 15
http://localhost 13
http://razasayed.com 10

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Git tech talk Git tech talk Presentation Transcript

  • Git : Awesome Distributed Version Control SystemGit : Awesome Distributed Version Control SystemPresenter : Raza.Z.Sayed
  • 2History● Linux kernel project● Patch emailing system● Bitkeeper from 2002 to 2005.● Why the name Git ?- “I’m an egotistical bastard, and I name all myprojects after myself.First Linux, now git.” – LinusTorvalds● First commit message : initial version of “git”,theinformation manager from hell-Linus 4/7/05
  • 3Basic Concepts●Git is not like SVN (Subversion) and is fundamentally different . Git trackscontent not changes or deltas●Its like a filesystem. Its a collection of tools that implement tree history storageand directory content management system.● Non linear development, distributed development and efficient- Ruby on Rails Git repository is around 13 Mb and Subversion repository ofthe same is around 115 Mb !● Not a binary but a toolkit design in spirit of unix philosophy (Write programsthat do one thing and do it well) View slide
  • 4Basic Concepts●Git Object Database → .git directory●Git Object Types → stored in .git/objects1. Blob2. Tree3. Commit4. Tag●Git Data Model1. Git Object Types2. References (Branches and Remotes) → stored in .git/refs View slide
  • 5Basic Git Workflow● mkdir my_awesome_project● cd my_awesome_project● git init● Create a file e.g. README.txt● git status (Optional)● git add README.txt (Add to staging)● git commit -m “first commit”
  • 6Basic Git Workflow● Make some changes to README.txt● Create a new file e.g. hello.rb● git status● git add hello.rb README.txt or git add . or git add --all● git commit -m “another commit”● Make changes to hello.rb● git commit -a -m “added foo method” (Wont adduntracked files to staging. git add them separately)
  • 7Different ways to add● git add <list of files> (Add the list of files)● git add --all (Add all files from the project.)● git add . (Add all files from the project)● git add *.txt (Add all txt files in current dir)● git add “*.txt” (Add all txt files from the project)● git add docs/*.txt (Add all txt files from docs dir)● git add docs/ (Add all files from docs dir)
  • 8Viewing changes● git diff (Show unstaged changes since lastcommit)● git diff --staged (show staged changes sincelast commit)● git log (show project history)
  • 9Undo unstaged changes● git checkout . (Blow away all changes sincelast commit)● git checkout <list of files> (Blow away changesto specified files since last commit)
  • 10Unstage changes● git reset HEAD (Unstage all staged files)● git reset HEAD <list of files> (Unstageparticular files) e.g. git reset HEADREADME.txt or git reset HEAD README.txthello.rb
  • 11Undo commits● git reset soft HEAD^ (Undo last commit and move changesback to staging) or git reset soft HEAD~1● git reset soft HEAD^^ (Undo last two commits and movechanges back to staging) or git reset soft HEAD~2● git reset hard HEAD^ (Undo last commit and blow away allchanges) or git reset hard HEAD~1● git reset hard HEAD^^^ (Undo last three commits and blowaway all changes) or git reset hard HEAD~3● git commit --amend -m “New commit message” (Changethe last commit message)
  • 12Sharing and Collaborating● Lots of different code hosting services tochoose from e.g. Unfuddle, Github, Bitbucketetc. or setup your own server.● Create a git repo on the server. This is called aremote repository.● Inside your project dir on your local machine :git remote add <some arbit name for theremote repo> <path of remote repo>
  • 13Sharing and Collaborating● git remote -v (show remote repositoriesassociated with the project)● git push -u <remote repo name> <branchname> e.g. git push -u origin master● git pull (Pull changes from the remote repo)● git remote rm <remote repo name> (Delete aremote repo from the project)
  • 14Sharing and Collaborating● Types of git repo urls : https://.. (Read only or readwrite depending upon permissions) , git://.. (Git readonly), git@.. (SSH read write)● git clone <remote repo url> or git clone <remote repourl> [local name]● git clone does the following three things. 1) Downloadsthe entire repo into a new directory 2) Adds originremote pointing it to clone url 3) checks out the masterbranch i.e. sets local repo HEAD to point to the masterbranch
  • 15Branching● Need to work on a new feature or fix a bug thatwill take time ?. Create a new branch to work onit.● git branch <branch name> (Creates the branch)● git checkout <branch name> (Switch to thebranch)● git checkout -b <branch name> (Shortcut tocreate and switch to a branch in one step)
  • 16Basic Branching Workflow● git checkout -b cool_feature● echo “This is readme for the cool feature” >README.txt● git add README.txt● git commit -m “first commit in cool_feature branch”● git checkout master● git merge cool_feature● git branch -d cool_feature (Delete the branch as weredone with it)
  • 17Types of Branch Merge● Fast Forward Merge● Non Fast Forward Merge (Recursive Merge)● Recursive Merge creates an extra commitautomatically called a “Merge commit”
  • 18Conflicts● Can either arise during git push or while doing amerge (merge conflict)● git push conflict scenario. Do a git pull first to fix● Two cases in which merge conflicts can arise. 1)During merging a local branch 2) Doing a git pull● git pull = git fetch+git merge. What is origin/master ?● Resolving merge conflicts
  • 19Sharing local branches●A wants to create a new branch and share it.git checkout -b awesome_new_featuregit push origin awesome_new_feature●B wants to collaborate on the new branch.git pullgit checkout awesome_new_feature●Listing remote branches : git branch -r●Getting detailed information about remote branches : git remote show origin●Deleting remote branches.git push origin :awesome_new_featuregit branch -d awesome_new_feature. If this does not work then,git branch -D awesome_new_feature●Cleaning up local references to deleted remote branches : git remote prune origin
  • 20Tagging● What are tags ?● Listing all tags : git tag● Creating a new tag : git tag -a v1.0 -m “version1.0”● Checkout code at a particular commit : gitcheckout v1.0● Sharing tags : git push --tags
  • 21Rebase● What is a rebase and why its better than a merge ?● Dont do git pull ! . Instead do a fetch + rebase.● Remote branch rebase workflowgit fetchgit rebase● Local branch rebase workflow. e.g. To rebase branch new_feature into mastergit checkout new_featuregit rebase mastergit checkout mastergit merge new_feature
  • 22Ignoring Files● Only for yourselfPut exclude patterns in .git/info/exclude file● For everyonePut exclude patterns in .gitignore file in theproject root directory● Untracking filesgit rm --cached <file name>
  • 23References● Git Community Book - http://git-scm.com/book● Git Branching -http://pcottle.github.com/learnGitBranching/● Git for computer scientists -http://eagain.net/articles/git-for-computer-scientists/● Visual Git Reference -http://marklodato.github.com/visual-git-guide/index-
  • 24Thank You