Slide 1

Slide 1 text

Git's not what you think it is Abizer Nasir

Slide 2

Slide 2 text

Why Am I Here? • I’ve been convincing people to use try git since 2009. • I’ve since become a version control “rubber duck”.

Slide 3

Slide 3 text

What This Talk Is Not • A git tutorial • Reasons to use X over any other DVCS • A handy list of commands for you to use

Slide 4

Slide 4 text

What I Will Talk About • Some misconceptions about Git and some different ways of thinking about Version control. • I prefer questions at the end, but please don’t let that stop you if you really want to raise your hand.

Slide 5

Slide 5 text

Git Is Not Just Version Control

Slide 6

Slide 6 text

Git Is A Safety Rope • Mark safe points as the code develops. • Easier to trash changes to a known point than to manually edit back to it. • Small, frequent changes that can be rolled up into more atomic commits. http://www.flickr.com/photos/mariachily/3382813383/

Slide 7

Slide 7 text

Git Is Communication • With your colleagues • With your clients • With your future or parallel self • A stored conversation about the history of a code base

Slide 8

Slide 8 text

Write Good Commit Messages • Short first line (less than 50 chars) in the present imperative tense. • “change” not “changes” • A blank line: • Body, wrapped to less than 80 chars, that provides more information about the commit. • Describe what applying the change will do, not what was done to create the change.

Slide 9

Slide 9 text

Example Fixes issue #X in production ! This change uses a algorithm Y which is faster than than W. ! - I’m using a bullet point, for a list of changes. - I usually don’t need to list the changed files.

Slide 10

Slide 10 text

Git Is Not A Silver Bullet

Slide 11

Slide 11 text

Help Git to Help You • Merge conflicts can still happen. Small commits that affect minimum subsets are easier to manage. • Git is not a substitute for project management. If many changes are happening to the same place in the same file, there will be conflicts. • Branches are cheap. Tags are cheap. Don’t be tempted to clean history too often. • Multiple repositories as backups are a good idea.

Slide 12

Slide 12 text

Git Allows History To Be Rewritten

Slide 13

Slide 13 text

“Git is evil because it lets you change history”

Slide 14

Slide 14 text

Changing History Is Bad When… • You change the history of any branch that somebody else is likely to have cloned and made changes to.

Slide 15

Slide 15 text

Changing History Is Not Bad When… • You are on a local branch that is not shared with anybody else. • You are on a branch that is synced with a private repository that only you use. • You roll up your list of small individual commits on your working branch into a larger atomic commit that you then push. • rebase is your friend. Seriously.

Slide 16

Slide 16 text

Reflog Is Your Lifeguard • Every change to HEAD is recorded. • State can be reconstructed using the shas.

Slide 17

Slide 17 text

Avoid pulling changes • Use `git fetch` and then inspect the upstream changes. • Use `git remote update` to fetch changes if the repository has multiple remotes. • Merge or rebase onto a temporary branch if you aren’t sure if the changes will apply cleanly.

Slide 18

Slide 18 text

You Don’t Need A GUI To Work With Git

Slide 19

Slide 19 text

gitk

Slide 20

Slide 20 text

git gui

Slide 21

Slide 21 text

git log --oneline

Slide 22

Slide 22 text

git log --graph --pretty=format:'%Cred%h %Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

Slide 23

Slide 23 text

Magit (emacs)

Slide 24

Slide 24 text

Git Is Not Just For Text Based Code

Slide 25

Slide 25 text

www.kaleidoscopeapp.com

Slide 26

Slide 26 text

Git Can Be Used With A Team Of Mixed Ability

Slide 27

Slide 27 text

Risks • Inexperienced team members (or clients) may mess up the repository. • History may be lost. • It could become hard to track development / test / production branches.

Slide 28

Slide 28 text

Protections • You don’t need to use every bit of git: add, push, commit, pull, fetch, checkout, status, are usually enough to get started • Git objects are immutable, changes are not irrevocable. Errors can be corrected. • Well named branches and a set of conventions are a great help. • Make people care, and they will care. Everyone wants to do a good job.

Slide 29

Slide 29 text

Git Flow • github.com/nvie/gitflow • datasift.github.io/gitflow • A set of scripts and workflows to define branching and merging. • Not everyone’s cup of tea but it helps when getting used to version control in a team.

Slide 30

Slide 30 text

Git Does Not Require Branches To Be Related

Slide 31

Slide 31 text

Independent Branches • I’m sure you’ve seen the gh-pages feature on github • `git checkout --orphan `

Slide 32

Slide 32 text

Branches Are Cheap • Never be afraid to create a branch. They are cheap. • Use some sort of naming convention so that you don’t get confused about them. • You can create a description for a branch • git branch --edit-description • If you want to park a branch - Create an annotated tag with a description.

Slide 33

Slide 33 text

Related Branches • Keep the main code in one branch. • Create a separate branch for a demo that uses the main code. • Use rebase liberally when only one branch is being used for development, but be sure to make it clear which the non-development branch is. • Use `cherry-pick` if changes are made in both branches.

Slide 34

Slide 34 text

Example

Slide 35

Slide 35 text

Git Is Not Hard

Slide 36

Slide 36 text

Err…

Slide 37

Slide 37 text

Git Can Be Difficult

Slide 38

Slide 38 text

132 Commands add am archive bisect branch bundle checkout cherry-pick citool clean clone commit describe diff fetch format-patch gc grep gui init log merge mv notes pull push rebase reset revert rm shortlog show stash status submodule tag gitk apply checkout-index commit-tree hash-object index-pack merge-file merge-index mktag mktree pack-objects prune-packed read-tree symbolic-ref unpack-objects update-index update-ref write-tree cat-file diff-files diff-index diff-tree for-each-ref ls-files ls-remote ls-tree merge-base name-rev pack-redundant rev-list show-index show-ref tar-tree unpack-file var verify-pack check-attr check-ref-format fmt-merge-msg mailinfo mailsplit merge-one-file patch-id peek-remote sh-setup stripspace daemon fetch-pack http-backend send-pack update-server-info http-fetch http-push parse-remote receive-pack shell upload-archive upload-pack config fast-export fast-import filter-branch lost-found mergetool pack-refs prune reflog relink remote repack replace repo-config annotate blame cherry count-objects difftool fsck get-tar-commit-id help instaweb merge-tree rerere rev-parse show-branch verify-tag whatchanged archimport cvsexportcommit cvsimport cvsserver imap-send quiltimport request-pull send-email svn

Slide 39

Slide 39 text

Porcelain / Plumbing add am archive bisect branch bundle checkout cherry-pick citool clean clone commit describe diff fetch format-patch gc grep gui init log merge mv notes pull push rebase reset revert rm shortlog show stash status submodule tag gitk apply checkout-index commit-tree hash-object index-pack merge-file merge-index mktag mktree pack-objects prune-packed read-tree symbolic-ref unpack-objects update-index update-ref write-tree cat-file diff-files diff-index diff-tree for-each-ref ls-files ls-remote ls-tree merge-base name-rev pack-redundant rev-list show-index show-ref tar-tree unpack-file var verify-pack check-attr check-ref-format fmt-merge-msg mailinfo mailsplit merge-one-file patch-id peek-remote sh-setup stripspace daemon fetch-pack http-backend send-pack update-server-info http-fetch http-push parse-remote receive-pack shell upload-archive upload-pack config fast-export fast-import filter-branch lost-found mergetool pack-refs prune reflog relink remote repack replace repo-config annotate blame cherry count-objects difftool fsck get-tar-commit-id help instaweb merge-tree rerere rev-parse show-branch verify-tag whatchanged archimport cvsexportcommit cvsimport cvsserver imap-send quiltimport request-pull send-email svn

Slide 40

Slide 40 text

You Don’t Need To Use It ALL • add • commit • fetch • merge • branch • checkout • push • status

Slide 41

Slide 41 text

Be Brave. Be Bold

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Start With The Basics • Use the basic commands to start with. Start using automation when you become comfortable with them. • Use a GUI if you have to. • If you want to do something complex, look it up and try to do it. Repetition builds knowledge. • Learn the Git object model, and everything becomes a lot clearer.

Slide 44

Slide 44 text

Be Brave, Bold, And Calm

Slide 45

Slide 45 text

Thank You! Abizer Nasir | @abizern | abizern.org | 365git.tumblr.com