The Unofficial

Guide to

Matt Gawarecki

2016-07-21

What we'll be covering

What would you say... you do here?

  • Basic overview
  • Navigation
  • Time travel
  • Making changes
  • Merging changes

PART 1

  • Branching methodologies

PART 2

PART 3

  • Scenario walkthroughs
  • Q & A

PART ONE

Fundamentals

Why Git's the best

  • It doesn't ask for much
  • It loves everyone
  • It trusts you completely
  • It's very fast
  • It's very powerful

I asked for a mai tai, and they brought me a pina colada, and I said no salt, NO salt for the margarita, but it had salt on it, big grains of salt, floating in the glass...

So that means that every single day that you see me, that's on the worst day of my life.

What about today? Is today the worst day of your life?

Yeah.

Wow, that's messed up.

RULE 1: Git flows downhill

Terminology

"PC LOAD LETTER"? What the f&*k does that mean?

  • remote: "the server"
    • you can have multiple
    • "origin" is the default
  • ref: a reference to a commit
  • HEAD: "YOU ARE HERE"
    • special "symbolic" ref
    • points to the last commit
  • index: staging area for commits

I almost forgot...

  • It's my presentation
  • It's the real deal
  • It's not going to lie to you

Why?

Starting off fresh

git init
  • Starts a brand new repository in the current directory
git clone <url> <directory>
  • Automatically checks out whatever origin/HEAD is
  • "directory" defaults to the directory you're in

  • "url" can be git://, SSH, HTTP(S), FTP(S), or a local file path

Michael, I did nothing. I did absolutely nothing, and it was everything that I thought it could be.

Getting around

​​git branch
  • List local branches, remote branches, or both
  • Create a new branch (without switching to it yet)
  • Some other cool tricks (ask me later)
git reset --hard <ref>
  • "Makes it look like nothing ever happened"
  • Restores working copy to what it looked like at <ref>, sets HEAD to point to <ref>, and clears the index
  • Has other advanced options that aren't used much
git checkout
  • Switch to any ref
  • Create a new branch and then switch to it automatically
  • Restore files from a different commit

Making changes

No way! Why should I change? He's the one who sucks.

git add
  • Add file(s) to the index
git rm
  • Remove file(s) from index and working copy
  • --cached: only the index
git mv
  • Move file(s) around in the index and working copy
git status
  • Status of the index
  • Current HEAD
  • Status relative to remote HEAD

Making changes

No way! Why should I change? He's the one who sucks.

git commit
  • Records changes in the index as a "real" commit in the repo
git push
  • Uploads local commits to the remote
git revert <refs...>
  • Makes a new commit that reverses the changes of other commit(s)

Keeping out the riff-raff

Yeah hi, it's Bill Lumbergh again...

.gitignore

  • Plaintext file in repo root
  • List of file/directory name patterns that should be ignored
  • Keeps files or directories from being tracked
  • DOES NOT affect files already tracked by the repository

Working with others

I stole something.

Yeah, I guess we all did.

No, I stole something else.

What did you steal?

We'll call it a going away present.

git fetch
  • Updates all refs to match remote
git stash <save|pop|apply>
  • saves the current working copy and the index to temp storage
  • clears index and working copy
  • allows later retrieval
git pull
  • fetch + merge
git merge <from>
  • Merges changes in <from> to current ref

Working with others

I stole something.

Yeah, I guess we all did.

No, I stole something else.

What did you steal?

We'll call it a going away present.

git rebase
  • Arguably the most powerful Git command
  • Lots of options
  • Re-write history to your liking
  • With great power comes great responsibility

Hardcore History

git log
  • Shows the commit log for the current ref
  • Lots of options (mostly visual)
git bisect
  • Interactive
  • Searches commit history to find when something changed
git blame
  • Shows who made the last change in a file, line by line
git diff
  • Shows the differences between two things
    • Refs, files, or directories

Break?

Questions?

PART TWO

Wherein I Monologue About Branching

To each his own

  • Release branching
    • One branch = one deployable release
  • Feature branching
    • One branch = one deliverable feature/bugfix
  • User branching
    • One branch = one user's changes
  • "Never-branch"
    • Everyone commits to master, all the time
  • Other workflows

Enter Gitflow

Enter Gitflow develop

Enter Gitflow features

Enter Gitflow releases

Enter Gitflow master

Enter Gitflow hotfixes

Enter Gitflow

PART THREE

Survival School

Some rules of thumb

  • DON'T PANIC
  • Commit early, commit often
  • Stay up-to-date
  • Push carefully
  • Everything's easier when it's local
  • Be courteous

Milton, don't be greedy. Let's pass it along and make sure everyone gets a piece.

Oops, I just...

Made a commit, but I messed up my commit message!

$> git commit --amend -m "My new message"

Oops, I just...

Created a branch with the wrong name!

$> git branch -m new-branch-name

Oops, I just...

Got one of these error messages:

error: Entry '<fileName>' not uptodate. Cannot merge. (Changes in working directory)
error: Entry '<fileName>' would be overwritten by merge. Cannot merge. (Changes in staging area)
$> git stash save
$> git add .
$> git commit -m "Committing my stuff"

OR

Oops, I just...

Got this error message:

CONFLICT (content): Merge conflict in <fileName>
Automatic merge failed; fix conflicts and then commit the result.

Fix your merge conflicts! Then...

$> git add .
$> git commit -m "My commit message"

Oops, I just...

Got myself into a nasty situation while merging and I want to back out!

$> git merge --abort

Oops, I just...

Successfully pushed a change, but now I need to take it back!

$> git revert HEAD
$> git push

Oops, I just...

Found out I have to fix something NOW,

but I've got important work that isn't ready to be committed!

$> git stash save
$> git stash pop

Do your work; then...

Oops, I just...

Found a bug, but I don't know where it's at or how to fix it!

$> git bisect start
$> git bisect bad
$> git bisect good <older-but-gooder-ref>

Thanks!

Contact Info

        matt.gawarecki@gmail.com

        Matt Gawarecki

        @mattgawarecki

Learning Resources

  • The official Git documentation
  • The first page of Google/Stack Overflow/etc.
  • Pro Git (free online / $60 paperback)
  • Internals: "Understanding Git Conceptually," sbf5.com
  • "Resolving merge conflicts in Git," is.gd/EC6Qec
  • Gitflow: "A successful Git branching model," nvie.com

Q & A: Last call

You see, it would be this mat that you would put on the floor, and it would have different "conclusions" written on it that you could "jump" to!

Made with Slides.com