GIT            THEORY            FOR            OPENby Forest   SOURCEMars                     11/4/30
“Using Git for web development islike Shopping for groceries in aFerrari”
Source                       SourceCode                         Code           SCCSControl                      ManagmentS...
Distributed       Version       Control       SystemDVCS
Distributed       Revision       Control       SystemDRCS
SpeedLightweightDistributedSecurityCode IntegrityEasy branching
GITTING STARTED                   LINUX$ sudo yum install git gitweb$ sudo aptitude install git-core gitweb               ...
Installing Git the Recommended Way:# GPG (if you didnt have it already)curl ftp://ftp.gnupg.org/gcrypt/gnupg/gnupg-1.4.7.t...
Installing Git the Recommended Way:# GITcurl http://kernel.org/pub/software/scm/git/git-1.5.5.tar.bz2 tar xjcd git-1.5.5./...
git config --global user.name "Forest Mars"git config --global user.emailforest@15382.no-reply.drupal.orggit config --glob...
git protocol$ git clonegit://github.com/drupal/drupal.git           http protocol$ git clonehttp://github.com/drupal/drupa...
git protocol$ git clonegit://git.drupal.org/project/drupal           http protocol$ git clonehttp://git.drupal.org/project...
PS1=[u@h W$(__git_ps1 " (%s)")]$ [forest@githubris gtfo (master)]:
$ gitusage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]           [-p|--paginate|--no-pager] [--no-replace...
$ git add .$ git commit -a -m “commitmessage”$ git push
WORKING WITH REMOTES$ git remote add origingit@host:repo-name.git$ git remote add originforest@git.drupal.org:sandbox/fore...
(What if I need to make my     repo bare later?)$ git config --bool core.bare true
Quite possibly the most   useful slide in this deck$ git describe$ git status$ git ls-files$ git diff$ git log --since=2.w...
Wait I was wrong, this is the    really important one:$ git commit --ammend$ git checkout HEAD some_file$ git revert HEAD^...
DONT LOSE YOUR HEAD  $ git checkout HEAD  $ git reset --hard HEAD
IN EVENT OF CATASTROPHIC FAILURE (or wheres the               Undo-Undo button?)[forest@githubris gtfo (master)]$ git add ...
CLONEFETCHCHECKOUTPRUNE
CLONEFETCHCHECKOUTPRUNE
git clone --branch 7.xgit://git.drupal.org/project/drupal.git ./
$ git clone --branch masterhttp://git.drupal.org:project/devel.git$ git clone -b 6.x-3.xgit://git.drupal.org/project/admin...
$ git clone --branch masterhttp://git.drupal.org:project/devel.git$ git clone -b 6.x-3.xgit://git.drupal.org/project/admin...
CLONE       FETCH       CHECKOUT       PRUNE$ got fetch origin[remote-branch]:[new-local-branch]
CLONE       FETCH       CHECKOUT       PRUNE$ git checkout -b some_branch origin/some_branch
CLONE       FETCH       CHECKOUT       PRUNE$ git remote prune -v [remote-repo]
BRANCHING
$ git branch  * master$ git branch new_branch$ git checkout -b new_branch[old_branch_name]$ git branch -r -d origin/[new_b...
$ git branch  * master    new_feature$ git merge new_feature$ git branch new_branch$ git rebase$ git pull --rebase$ git re...
PUSH ME PULL YOU$ git push$ git push origin master$ git push origin [branch-name]$ git push [remote-repo]LOCALBRANCHNAME:R...
The Dirtiest Git Hack You Will Ever                 See$ git push upstreamupstreammaster:master! [rejected] master -> mast...
$ git clone forest@git.drupal.org:sandbox/forest//1140078.gitCloning into /1140078...forest@git.drupal.orgs password:
$ git clone forest@git.drupal.org:sandbox/forest//1140078.gitCloning into /1140078...forest@git.drupal.orgs password:$ git...
$ echo name = "My Awesome Module" >1140078.info$ echo <?php> > my_awesome.module
$ git status On branch master Initial commit Untracked files:   (use "git add <file>..." to include inwhat will be committ...
$ git add .$ git commit -m “initial commit”$ git push origin masterCounting objects: 5, done.Delta compression using up to...
linkedin.com/in/forestmars    twitter.com/forestmars       about.me/forestmars                   THANX!                  t...
Adding Bash Completion for Git on Mac OS X Snow Leopard                             cd /tmp && git clone                  ...
GTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSource
Upcoming SlideShare
Loading in...5
×

GTFO: Git Theory For OpenSource

1,907

Published on

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

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,907
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

GTFO: Git Theory For OpenSource

  1. 1. GIT THEORY FOR OPENby Forest SOURCEMars 11/4/30
  2. 2. “Using Git for web development islike Shopping for groceries in aFerrari”
  3. 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. 4. Distributed Version Control SystemDVCS
  5. 5. Distributed Revision Control SystemDRCS
  6. 6. SpeedLightweightDistributedSecurityCode IntegrityEasy branching
  7. 7. GITTING STARTED LINUX$ sudo yum install git gitweb$ sudo aptitude install git-core gitweb OSX$ sudo port install git-coreosx-git-installer:code.google.com/p/git-osx-installer/
  8. 8. Installing Git the Recommended Way:# GPG (if you didnt have it already)curl ftp://ftp.gnupg.org/gcrypt/gnupg/gnupg-1.4.7.tar.bz2 tar xjcd gnupg-1.4.7./configuremakesudo make installcd ..# GetTextcurl http://mirrors.usc.edu/pub/gnu/gettext/gettext-0.17.tar.gz tar xzcd gettext-0.17./configuremakesudo make installcd ..
  9. 9. Installing Git the Recommended Way:# GITcurl http://kernel.org/pub/software/scm/git/git-1.5.5.tar.bz2 tar xjcd git-1.5.5./configuremakesudo make installcd ..curl http://www.kernel.org/pub/software/scm/git/git-manpages-1.5.5.tar.bz2 sudo tar xj -C /usr/local/share/man
  10. 10. git config --global user.name "Forest Mars"git config --global user.emailforest@15382.no-reply.drupal.orggit config --global user.xmpp“twitter.com/forestmars”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. 11. git protocol$ git clonegit://github.com/drupal/drupal.git http protocol$ git clonehttp://github.com/drupal/drupal.git
  12. 12. git protocol$ git clonegit://git.drupal.org/project/drupal http protocol$ git clonehttp://git.drupal.org/project/drupal
  13. 13. PS1=[u@h W$(__git_ps1 " (%s)")]$ [forest@githubris gtfo (master)]:
  14. 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. 15. $ git add .$ git commit -a -m “commitmessage”$ git push
  16. 16. WORKING WITH REMOTES$ git remote add origingit@host:repo-name.git$ git remote add originforest@git.drupal.org:sandbox/forest/project.git$ git remote add githubgit@github.com:forestmars/example.git$ git remote -v
  17. 17. (What if I need to make my repo bare later?)$ git config --bool core.bare true
  18. 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. 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. 20. DONT LOSE YOUR HEAD $ git checkout HEAD $ git reset --hard HEAD
  21. 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
  22. 22. CLONEFETCHCHECKOUTPRUNE
  23. 23. CLONEFETCHCHECKOUTPRUNE
  24. 24. git clone --branch 7.xgit://git.drupal.org/project/drupal.git ./
  25. 25. $ git clone --branch masterhttp://git.drupal.org:project/devel.git$ git clone -b 6.x-3.xgit://git.drupal.org/project/admin_menu.git$ git clone --branch 7.xgit://git.drupal.org/project/some_module.git./$ cd some_module$ (edit files)$ git add (files)$ git commit -m Explain what I changed
  26. 26. $ git clone --branch masterhttp://git.drupal.org:project/devel.git$ git clone -b 6.x-3.xgit://git.drupal.org/project/admin_menu.git$ git clone --branch 7.xgit://git.drupal.org/project/some_module.git./$ cd some_module$ (edit files)$ git add (files)$ git commit -m Explain what I changed
  27. 27. CLONE FETCH CHECKOUT PRUNE$ got fetch origin[remote-branch]:[new-local-branch]
  28. 28. CLONE FETCH CHECKOUT PRUNE$ git checkout -b some_branch origin/some_branch
  29. 29. CLONE FETCH CHECKOUT PRUNE$ git remote prune -v [remote-repo]
  30. 30. BRANCHING
  31. 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. 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. 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. 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. 35. $ git clone forest@git.drupal.org:sandbox/forest//1140078.gitCloning into /1140078...forest@git.drupal.orgs password:
  36. 36. $ git clone forest@git.drupal.org:sandbox/forest//1140078.gitCloning into /1140078...forest@git.drupal.orgs password:$ git clone git@git.drupal.org:sandbox/forest//1140078.gitCloning into /1140078...
  37. 37. $ echo name = "My Awesome Module" >1140078.info$ echo <?php> > my_awesome.module
  38. 38. $ git status On branch master Initial commit Untracked files: (use "git add <file>..." to include inwhat will be committed) 1140078.info my_awesome.modulenothing added to commit but untracked filespresent (use "git add" to track)
  39. 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)Toforest@git.drupal.org:sandbox/forest//1140078.git 1a8d48d..f6dcf5d master -> master
  40. 40. linkedin.com/in/forestmars twitter.com/forestmars about.me/forestmars THANX! twitter.com/forestmars
  41. 41. Adding Bash Completion for Git on Mac OS X Snow Leopard cd /tmp && git clone git://git.kernel.org/pub/scm/g 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 [ -ftwitter.com/forestmars /opt/local/etc/bash_completion ]; then . /opt/local/etc/bash_completion fi
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×