10. git > svn
• Distributed
• Every git repository is self-contained and
includes a complete history of commits.
(i.e. `git clone ...` vs `svn checkout ...`)
11. git > svn
• Distributed
• Every git repository is self-contained and
includes a complete history of commits.
(i.e. `git clone ...` vs `svn checkout ...`)
• You can commit/branch/merge locally.
Read: Fast & offline.
12. git > svn
• Distributed
• Every git repository is self-contained and
includes a complete history of commits.
(i.e. `git clone ...` vs `svn checkout ...`)
• You can commit/branch/merge locally.
Read: Fast & offline.
• No single point of failure.
13. git > svn
• Distributed
• Every git repository is self-contained and
includes a complete history of commits.
(i.e. `git clone ...` vs `svn checkout ...`)
• You can commit/branch/merge locally.
Read: Fast & offline.
• No single point of failure.
• No “latest revision”: unique revision ID
14. git > svn
• Lightweight Branching
• Branch and merge often (per feature?)
17. git > svn
• Small Space Requirements
• Ex: Mozilla: SVN:12GB => git:420MB
18. git > svn
• git submodules vs svn externals
• Not covered in this presentation
19. A couple new concepts
• “Remote” or “upstream”: A remotely
accessible repository.
• Push to a remote
• Pull from a remote
20. A couple new concepts
• “Staging area” or “index”: What will go into
your next commit.
• Example:
• mate new_file.rb <= not staged
• git add new_file.rb <= staged
• git commit -a -m “Added a new file.”
• Staging area is now empty.
25. Get Git Started
• Install on OSX
• git-osx-installer - Recommended.
• OR
• sudo port install git-core +svn +doc +bash_completion +gitweb
26. Get Git Started
• Configure your user
• git config --global user.name "Bobby SV"
• git config --global user.email
"bob@sv.com"
27. git commands: basics
git init Initialize a git repository.
git add Add files to a repository.
git diff Generate a diff.
git status Show uncommitted changes to the current project.
git rm Remove a file from a repository.
git mv Moves a file within a repository.
git commit Commits staged changes. Use ‘-a’ to automatically stage every file that is
already tracked before doing the commit.
git log View a log of commits.
git blame Show what revision and author last modified each line of a file.
git show View the contents of a file, the listing of a directory or a commit.
28. git commands: branches
git tag -a name Add a tag with the indicated name.
git tag -l List tags.
git push --tags Push tags to remote.
git branch name Create a branch with the indicated name.
git checkout name Switches to the branch ‘name’.
git branch -a List branches (current branch indicated with ‘*’).
git merge name Merge changes from branch name into the current branch.
git cherry-pick rev Apply the changes in revision rev and commit to the current branch.
git branch -d name Deletes the named branch.
29. git commands: remote
git clone url Clone a repository. Sets up master branch w/ origin remote.
git fetch Fetch updates from a remote repository.
git pull git fetch + git merge - Use this more often than either alone.
git remote List remotes.
git push remote local_branch Push changes to remote. (remote & local_branch are optional)
git remote add url Add a remote branch to the repository at url.
git remote show remote Shows the branches in the remote repository.
30. git commands: advanced
git checkout --track -b branch origin/
Create a corresponding local branch which will "track" the remote branch
branch
git stash Store uncommitted changes and reverts to HEAD.
git rebase Provides fine-grained control of commits. Allows you to take all the changes that
were committed on one branch and replay them on another one.
git revert Undo a previous commit. Very different from `svn revert file` (which would be
done with `git checkout file`or `git reset --hard HEAD`)
git format-patch Prepare a patch for other developers.
git fsck Check for errors.
git gc --prune Cleanup repository.
git grep “foo()” Search working directory for foo().
git merge --squash branch Represent many commits as one commit.
git whatchanged Show the differences between commits.
git show HEAD~4 HEAD~4 is short for HEAD^^^^. Each ‘^’ represents a parent revision.
33. Flow #1: simple/local
• cd project_cornice
• git init
• Set up your ignores (next slide)
• git add .
• git commit -a -m "Initial import."
• mate file.rb (make changes)
• git commit -a -m "Make file better."
34. Flow #1: simple/local
• More on .gitignore files
• Like SVN’s `svn propset ignore`
• For example, in project root,
add .gitignore containing:
• log/*.log
• tmp/**/*