Your SlideShare is downloading. ×

GTFO: Git Theory For OpenSource


Published on

Slides from a talk I gave in New York on Git in theory, Git in practice and Git-Drupal use cases.

Slides from a talk I gave in New York on Git in theory, Git in practice and Git-Drupal use cases.

Published in: Technology

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. GIT THEORY FOR OPENby Forest SOURCEMars 11/4/30
  • 2. “Using Git for web development islike Shopping for groceries in aFerrari”
  • 3. Source SourceCode Code SCCSControl ManagmentSystem VCS SoftwareSoftware SVSC Configuration ManagementVersion RCS SVCControl ConcurrentSystem SCM Versioning SystemVersion SCMS SCM CentralisedControlSystem CVS Version System Version
  • 4. Distributed Version Control SystemDVCS
  • 5. Distributed Revision Control SystemDRCS
  • 6. SpeedLightweightDistributedSecurityCode IntegrityEasy branching
  • 7. GITTING STARTED LINUX$ sudo yum install git gitweb$ sudo aptitude install git-core gitweb OSX$ sudo port install
  • 8. Installing Git the Recommended Way:# GPG (if you didnt have it already)curl tar xjcd gnupg-1.4.7./configuremakesudo make installcd ..# GetTextcurl tar xzcd gettext-0.17./configuremakesudo make installcd ..
  • 9. Installing Git the Recommended Way:# GITcurl tar xjcd git-1.5.5./configuremakesudo make installcd ..curl sudo tar xj -C /usr/local/share/man
  • 10. git config --global "Forest Mars"git config --global config --global user.xmpp“”git config --global user.irc“kombucha”$ git config --global color.status auto$ git config --global color.branch auto$ git config --global color.diff auto
  • 11. git protocol$ git clonegit:// http protocol$ git clone
  • 12. git protocol$ git clonegit:// http protocol$ git clone
  • 13. PS1=[u@h W$(__git_ps1 " (%s)")]$ [forest@githubris gtfo (master)]:
  • 14. $ gitusage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path] [-p|--paginate|--no-pager] [--no-replace-objects] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [-c name=value] [--help] COMMAND [ARGS]The most commonly used git commands are: add Add file contents to the index bisect Find by binary search the change that introduced a bug branch List, create, or delete branches checkout Checkout a branch or paths to the working tree clone Clone a repository into a new directory commit Record changes to the repository diff Show changes between commits, commit and working tree, etc fetch Download objects and refs from another repository grep Print lines matching a pattern init Create an empty git repository or reinitialize an existing one log Show commit logs merge Join two or more development histories together mv Move or rename a file, a directory, or a symlink pull Fetch from and merge with another repository or a local branch push Update remote refs along with associated objects rebase Forward-port local commits to the updated upstream head reset Reset current HEAD to the specified state rm Remove files from the working tree and from the index show Show various types of objects status Show the working tree status tag Create, list, delete or verify a tag object signed with GPG
  • 15. $ git add .$ git commit -a -m “commitmessage”$ git push
  • 16. WORKING WITH REMOTES$ git remote add origingit@host:repo-name.git$ git remote add$ git remote add$ git remote -v
  • 17. (What if I need to make my repo bare later?)$ git config --bool core.bare true
  • 18. Quite possibly the most useful slide in this deck$ git describe$ git status$ git ls-files$ git diff$ git log --since=2.weeks$ git foo –help
  • 19. Wait I was wrong, this is the really important one:$ git commit --ammend$ git checkout HEAD some_file$ git revert HEAD^$ git revert HEAD~1 -m 1$ git reset --hard HEAD$ git reset --hard [reflog-id]
  • 20. DONT LOSE YOUR HEAD $ git checkout HEAD $ git reset --hard HEAD
  • 21. IN EVENT OF CATASTROPHIC FAILURE (or wheres the Undo-Undo button?)[forest@githubris gtfo (master)]$ git add somefile[forest@githubris gtfo (master)]$ git commit -m "updated some file"[master 7ff5b1e] updated some file 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 somefile[forest@githubris gtfo (master)]$ cat somefilecontents of somefile[forest@githubris gtfo (master)]$ git reset --hard HEAD^HEAD is now at 15dae3b somefile[forest@githubris gtfo (master)]$ cat somefilecat: otherfile: No such file or directory[forest@baird gtfo (master)]$ git reflog15dae3b HEAD@{0}: HEAD^: updating HEAD7ff5b1e HEAD@{1}: commit: updated some file[forest@githubris gtfo (master)]$ git reset --hard 7ff5b1eHEAD is now at 7ff5b1e updated some file[forest@githubris gtfo (master)]$ cat somefile
  • 24. git clone --branch 7.xgit:// ./
  • 25. $ git clone --branch master$ git clone -b 6.x-3.xgit://$ git clone --branch 7.xgit://$ cd some_module$ (edit files)$ git add (files)$ git commit -m Explain what I changed
  • 26. $ git clone --branch master$ git clone -b 6.x-3.xgit://$ git clone --branch 7.xgit://$ cd some_module$ (edit files)$ git add (files)$ git commit -m Explain what I changed
  • 27. CLONE FETCH CHECKOUT PRUNE$ got fetch origin[remote-branch]:[new-local-branch]
  • 28. CLONE FETCH CHECKOUT PRUNE$ git checkout -b some_branch origin/some_branch
  • 29. CLONE FETCH CHECKOUT PRUNE$ git remote prune -v [remote-repo]
  • 31. $ git branch * master$ git branch new_branch$ git checkout -b new_branch[old_branch_name]$ git branch -r -d origin/[new_branch_name]$ git branch --track ... origin/...
  • 32. $ git branch * master new_feature$ git merge new_feature$ git branch new_branch$ git rebase$ git pull --rebase$ git rebase -i$ git rebase
  • 33. PUSH ME PULL YOU$ git push$ git push origin master$ git push origin [branch-name]$ git push [remote-repo]LOCALBRANCHNAME:REMOTEBRANCHNAME default behavior of git is to push matching refs, so git push <remote-repo> would not push branch if it is notpresent on <remote-repo>$ git push -f –allOnce the local branch is pushed to the remote, execute:$ git --set-upstream [local-branch] origin/[branch-name]to make the local branch track the remote branch.$ git push -n --dryrun
  • 34. The Dirtiest Git Hack You Will Ever See$ git push upstreamupstreammaster:master! [rejected] master -> master (non-fast forward)$ git push origin :master$ git push origin master
  • 35. $ git clone into /1140078...forest@git.drupal.orgs password:
  • 36. $ git clone into /1140078...forest@git.drupal.orgs password:$ git clone into /1140078...
  • 37. $ echo name = "My Awesome Module" >$ echo <?php> > my_awesome.module
  • 38. $ git status On branch master Initial commit Untracked files: (use "git add <file>..." to include inwhat will be committed) my_awesome.modulenothing added to commit but untracked filespresent (use "git add" to track)
  • 39. $ git add .$ git commit -m “initial commit”$ git push origin masterCounting objects: 5, done.Delta compression using up to 4 threads.Compressing objects: 100% (3/3), done.Writing objects: 100% (3/3), 300 bytes,done.Total 3 (delta 2), reused 0 (delta 0) 1a8d48d..f6dcf5d master -> master
  • 40. THANX!
  • 41. Adding Bash Completion for Git on Mac OS X Snow Leopard cd /tmp && git clone git:// it/git.git cd git && git checkout v`git --version | awk {print $3}` cp contrib/completion/git- completion.bash ~/.git- completion.bash Cd ~ && rm -rf /tmp/git echo -e "source ~/.git- completion.bash" >> .profile sudo port install git-core +bash_completion if [ /opt/local/etc/bash_completion ]; then . /opt/local/etc/bash_completion fi