GTFO: Git Theory For OpenSource
Upcoming SlideShare
Loading in...5
×
 

GTFO: Git Theory For OpenSource

on

  • 2,095 views

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.

Statistics

Views

Total Views
2,095
Views on SlideShare
2,090
Embed Views
5

Actions

Likes
0
Downloads
6
Comments
0

2 Embeds 5

https://twitter.com 3
http://paper.li 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

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

GTFO: Git Theory For OpenSource GTFO: Git Theory For OpenSource Presentation Transcript

  • GIT THEORY FOR OPENby Forest SOURCEMars 11/4/30
  • “Using Git for web development islike Shopping for groceries in aFerrari”
  • Source SourceCode Code SCCSControl ManagmentSystem VCS SoftwareSoftware SVSC Configuration ManagementVersion RCS SVCControl ConcurrentSystem SCM Versioning SystemVersion SCMS SCM CentralisedControlSystem CVS Version System Version
  • 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 OSX$ sudo port install git-coreosx-git-installer:code.google.com/p/git-osx-installer/
  • 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 ..
  • 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
  • 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
  • git protocol$ git clonegit://github.com/drupal/drupal.git http protocol$ git clonehttp://github.com/drupal/drupal.git
  • git protocol$ git clonegit://git.drupal.org/project/drupal http protocol$ git clonehttp://git.drupal.org/project/drupal
  • 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-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
  • $ 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/forest/project.git$ git remote add githubgit@github.com:forestmars/example.git$ git remote -v
  • (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.weeks$ git foo –help
  • 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]
  • 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 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
  • 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_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
  • $ 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
  • 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_branch_name]$ git branch --track ... origin/...
  • $ git branch * master new_feature$ git merge new_feature$ git branch new_branch$ git rebase$ git pull --rebase$ git rebase -i$ git rebase
  • 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
  • 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
  • $ 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 clone git@git.drupal.org:sandbox/forest//1140078.gitCloning into /1140078...
  • $ 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 committed) 1140078.info my_awesome.modulenothing added to commit but untracked filespresent (use "git add" to track)
  • $ 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
  • linkedin.com/in/forestmars twitter.com/forestmars about.me/forestmars THANX! twitter.com/forestmars
  • 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