All Things Git

Git, GitHub, Git Hooks & More

Alex DiLiberto

@alex_diliberto

alexdiliberto.com

Version Control?

git

  • 2005
  • Linus Torvalds
  • Open source
  • Distributed version control
tux

“Open source is the only right way to do software.”

Linus

Why should I care?

  1. Community adoption
  2. Decentralized
  3. Performance
  4. Data assurance
  5. Free/open source
  6. octocat open source initiative

Time to shift our thinking

SVN

SVN repository

Git

Git repository
SVN repository
Git repository

Basic Commands

init, clone, add, commit, log, status

Show init, add, commit and log
Show clone and status

Branching

Show an example of a snapshot of commits

$ git commit -m 'initial commit of my project';

$ git commit -m 'fixed bug #1328...';

$ git commit -m 'add feature #32...';

Show an example of a snapshot of commits Master branch pointer HEAD pointer

Branch - simply a lightweight movable pointer to a single commit.

Show an example of a snapshot of commits master branch pointer HEAD pointer testing branch pointer

$ git branch testing;

Merge vs Rebase

What happened here?

Merge vs Rebase

Also...

git pull --rebase

Git on the Server

Git on the server
  • Simple Bare Repository
    • Quick
  • Github
    • User centric hosted solution
  • GitLab/Phabricator
    • Self hosted
  • Gitolite
    • Access control layer sits on top of git
    • Single UNIX hosting user / Many “virtual” users
    • Simple yet powerful
    • Security with SSH based authentication

Lightweight

Transparent

Scalable

Workflows

Gitflow

Gitflow

gem install gitflow

Forking

Forking

.git/hooks

pre-commit

post-commit

pre-rebase

post-checkout

post-merge

pre-receive

post-receive

update

Things we didn't cover in detail

$ git diff

Forking

$ git (revert|reset)

Forking
  • Tagging
  • Git Config
    • user.name / user.email
  • Branch traversal and detached HEAD state
  • Ancestors and Commit Ranges
    • $ git show HEAD^
    • $ git show feature~3
    • $ git log origin/master..HEAD
  • Undoing Changes
    • $ git revert HEAD~2
    • $ git reset HEAD^
  • $ git stash
  • Remote branches
  • ReFlog

Do's, Don'ts, & Best Practices

Commit often, Perfect later, Publish once

Branch early, branch often

Use your scratch pads

Don't panic

git reflog,  git fsck,  git stash

Do follow a workflow

Do write useful commit messages

Don't rewrite (public) history

BTTF

All Your Rebase

BTTF

git pull –rebase

git rebase –i

Do enforce standards

hooks, testing, proper commit messages, workflows, merging vs rebasing, and more

Do Backup

$ git bundle create /tmp/my-project.backup --all

References

Thanks!

Alex DiLiberto

@alex_diliberto

alexdiliberto.com