gtfo: git theory for opensource
DESCRIPTION
Slides from a talk I gave in New York on Git in theory, Git in practice and Git-Drupal use cases.TRANSCRIPT
GITTHEORYFOROPENSOURCEby Forest
Mars
11/4/30
“Using Git for web development is like Shopping for groceries in a Ferrari”
SCCS
SVC
Source
Code
Managment
Software
Configuration
Management
Concurrent
Versioning
System
Centralised
Version
System
Version
Control
System
CVSSCM
VCSSVSC
SCM
Source
Code
Control
System
Software
Version
Control
System
Version
Control
System
RCS
SCMS
Distributed
Version
Control
System
DVCS
Distributed
Revision
Control
System
DRCS
Speed
Lightweight
Distributed
Security
Code Integrity
Easy branching
GITTING STARTED
LINUX
$ sudo yum install git gitweb
$ sudo aptitude install git-core gitweb
OSX
$ sudo port install git-core
osx-git-installer:code.google.com/p/git-osx-installer/
Installing Git the Recommended Way:
# GPG (if you didn't 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.email [email protected]
git 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 config --global color.interactive auto
git protocol
$ git clone git://github.com/drupal/drupal.git
http protocol
$ git clone http://github.com/drupal/drupal.git
git protocol
$ git clone git://git.drupal.org/project/drupal
http protocol
$ git clone http://git.drupal.org/project/drupal
PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
[forest@githubris gtfo (master)]:
$ git
usage: 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 init
$ git add .
$ git commit -a -m “commit message”
$ git push
WORKING WITH REMOTES
$ git remote add origingit@host:repo-name.git
$ git remote add origin [email protected]:sandbox/forest/project.git
$ git remote add github [email protected]: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
$ cat .git/config
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]
DON'T LOSE YOUR HEAD
$ git checkout HEAD
$ git reset --hard HEAD
IN EVENT OF CATASTROPHIC FAILURE (or where's 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 somefile contents of somefile
[forest@githubris gtfo (master)]$ git reset --hard HEAD^HEAD is now at 15dae3b somefile
[forest@githubris gtfo (master)]$ cat somefile cat: 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 contents of somefile
CLONE
FETCH
CHECKOUT
PRUNE
CLONE
FETCH
CHECKOUT
PRUNE
git clone --branch 7.x git://git.drupal.org/project/drupal.git ./git clone --branch 7.x git://git.drupal.org/project/drupal.git ./
$ git clone --branch master http://git.drupal.org:project/devel.git
$ git clone -b '6.x-3.x' git://git.drupal.org/project/admin_menu.git
$ git clone --branch 7.x git://git.drupal.org/project/some_module.git ./
$ cd some_module
$ (edit files)
$ git add (files)
$ git commit -m 'Explain what I changed'
$ git format-patch origin/master
$ git clone --branch master http://git.drupal.org:project/devel.git
$ git clone -b '6.x-3.x' git://git.drupal.org/project/admin_menu.git
$ git clone --branch 7.x git://git.drupal.org/project/some_module.git ./
$ cd some_module
$ (edit files)
$ git add (files)
$ git commit -m 'Explain what I changed'
$ git format-patch origin/master
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]
B R A N C H I N G
$ 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
$ 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 not present on <remote-repo>
$ git push -f –all
Once 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
$ git push REMOTENAME :BRANCHNAME
PUSH ME PULL YOU
$ git push upstream upstreammaster:master! [rejected] master -> master (non-fast forward)
$ git push origin :master
$ git push origin master
The Dirtiest Git Hack You Will Ever See
$ git clone [email protected]:sandbox/forest//1140078.git
Cloning into /1140078...
[email protected]'s password:
$ git clone [email protected]:sandbox/forest//1140078.git
Cloning into /1140078...
[email protected]'s password:
$ git clone [email protected] :sandbox/forest//1140078.git
Cloning 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 in what will be committed)
1140078.infomy_awesome.module
nothing added to commit but untracked files present (use "git add" to track)
$ git add .
$ git commit -m “initial commit”
$ git push origin master
Counting 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)To [email protected]:sandbox/forest//1140078.git 1a8d48d..f6dcf5d master -> master
twitter.com/forestmarsT H A N X !
linkedin.com/in/forestmars
twitter.com/forestmars
about.me/forestmars
twitter.com/forestmars
Adding Bash Completion for Git on Mac OS X Snow Leopard
cd /tmp && git clone git://git.kernel.org/pub/scm/git/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/gitecho -e "source ~/.git-completion.bash" >> .profile
sudo port install git-core +bash_completion
if [ -f /opt/local/etc/bash_completion ]; then . /opt/local/etc/bash_completionfi