67
Git Quickstart Revision Control for Rock Stars

Git One Day Training Notes

Embed Size (px)

DESCRIPTION

Download the powerpoint and checkout the speaker notes for some ideas around exercises.

Citation preview

Page 1: Git One Day Training Notes

Git Quickstart

Revision Control for Rock Stars

Page 2: Git One Day Training Notes

Introductions

How would you know this course was valuable a week from now?

Page 3: Git One Day Training Notes

Course Outline

• Getting Setup• Git: The Big Picture• Everyday Git• Branching• Merging & Rebasing• Other Random Gitness• Putting It All Together• Where to from here?

Page 4: Git One Day Training Notes

Outcomes & Compentencies

• Install and Configure Git for Windows• Create local and shared Git repos• Add, Remove & Commit Files to repos• View History of Files / Work with Diffs & Blames• Branch, Tag and Merge & Rebase Branches

(with Conflicts)• Back out of trouble & drama• Be able to Push, Pull, Fetch, Clone, Diff &

Branch Remote Repos• Formulating Team Workflows with Git

Page 5: Git One Day Training Notes

Philosophy

• “One must learn by doing the thing; for though you think you know it, you have no certainty, until you try.” Sophocles

• “Where there are no oxen, the manger is clean, but abundant crops come by the strength of an ox.” Jewish Proverb.

• Experiment. Go Crazy. Type like a madman.

Page 6: Git One Day Training Notes

MODULE 0: GIT - THE BIG PICTURE

What? When? Why?

Page 7: Git One Day Training Notes

Git: The Big Picture

Page 8: Git One Day Training Notes

Use Cases

• Individual Developer• Local Workgroup• Distributed Workgroup• Offline Usages

Page 9: Git One Day Training Notes

Git vs Svn vs CVS vs ?

• Snapshots, not diffs• Blobs• Everything is local• Everything is fast

Page 10: Git One Day Training Notes

What’s This “Commit” Thing?

7ef7ab ef3ad2 22e4ff

File1.txtFile2.txt

File3.txtFile1.txt

File4.txt

Page 11: Git One Day Training Notes

Git WorkflowWorkin

g Directo

ryStaging

Area (Index)

Repository

Add

Commit

Checkout

Page 12: Git One Day Training Notes

1. GETTING SETUPGetting things installed…

Page 13: Git One Day Training Notes

GUIs or Commandline or IDE?

• Git Bash• Posh Git (Powershell)• GitHub for Windows• Tortoise Git• Eclipse Git / IntelliJ Git / Visual Studio

Git Plugin / etc

Page 14: Git One Day Training Notes

Download Git for Windows

Page 15: Git One Day Training Notes

Installation Options

Page 16: Git One Day Training Notes

The Magic Path Dialog

Page 17: Git One Day Training Notes

Checkout Conventions

Page 18: Git One Day Training Notes

Commandline Once-off Magic

• git config --global user.name “Glen Smith”

• git config --global user.email “[email protected]

• git config -l [--global]• git help config

Page 19: Git One Day Training Notes

MODULE 2: EVERYDAY GITThings you’ll use every single day…

Page 20: Git One Day Training Notes

Everyday Git: Getting Committed

• git init .• git init myproject

• git status

• echo This is a sample file > sample.txt

Page 21: Git One Day Training Notes

Adding and Committing

• git add .• git add myfile.txt myotherfile.txt• git add “**.txt”• git status• git commit -m “My first commit!”• git commit• git commit -am “Add all files and

commit. I live on the edge”

Page 22: Git One Day Training Notes

Formatting Commits

• set GIT_EDITOR=notepad• git config --global core.editor

“notepad“

• First line for short form.• Second line blank.• Third line for a long description of the

commit

Page 23: Git One Day Training Notes

Diff & Blame

• git diff• git blame /path/to/my/file.txt• git gui blame /path/to/my/file.txt• git whatchanged /path/to/my/file.txt • gitk /path/to/my/file.txt

Page 24: Git One Day Training Notes

Viewing History

• git log • git log --oneline• git log --oneline -3• git log -p• git log --since “last week” --until “2

days ago”• gitk

Page 25: Git One Day Training Notes

What’s with the SHA1?

Page 26: Git One Day Training Notes

Deleting and Renaming Files

• git rm badfile.txt

• git mv oldname.txt newname.txt

• git clean -n (dry run)• git clean -f (force)

Page 27: Git One Day Training Notes

Ignoring Files

• .gitignore• Ignore file(s), directories, patterns

(one per line)• Great for ignoring files and

directories in your project• Specially good for build artefacts and

generated binaries

Page 28: Git One Day Training Notes

Unstaging a File

• git reset HEAD myfile.txt• git checkout myfile.txt• git rm –cached myfile (only pre first

commit)

Page 29: Git One Day Training Notes

Amending A Commit

• (stage the files you want)• git commit --amend

Page 30: Git One Day Training Notes

The Reflog

• git reflog• git checkout <your-commit-sha1>• git checkout master

Page 31: Git One Day Training Notes

MODULE 3: BRANCHING & TAGGING

Working with Lines of Development

Page 32: Git One Day Training Notes

Our Story So Far…

7ef7ab ef3ad2 22e4ff

Page 33: Git One Day Training Notes

What could you use branches for?

• Bug fixes• Experimental features• Release branches• Integration Branches (CI)

Page 34: Git One Day Training Notes

In Reality…

7ef7ab ef3ad2 22e4ff

ab4efa 6e3fd1

ee7ee7

Developer Branches for

an experimental

feature..

Merges his Changes back to the master

Page 35: Git One Day Training Notes

Branching

• git branch• git branch mynewbranch• git checkout mynewbranch• git checkout -b

mynewcheckedoutbranch• git branch -d deletethatbranch

Page 36: Git One Day Training Notes

Stashing

• git stash• git stash list• git stash apply• git stash pop• git stash clear

Page 37: Git One Day Training Notes

Merging

• git merge branchname• git log master..dev

22e4ff

6e3fd1

ee7ee7

Merge creates a new commit with two parents

Page 38: Git One Day Training Notes

Handling Conflicts

• git status• git checkout --ours myfile.txt• git checkout --theirs theirfile.txt

Page 39: Git One Day Training Notes

Helpful Branch Tools

• gitk• git log --graph --oneline

Page 40: Git One Day Training Notes

Tagging

• git tag 1.0• git tag -f 1.0• git tag -a 1.0• git tag

Page 41: Git One Day Training Notes

Working with Remotes

• mkdir ourrepo.git• cd ourrepo.git• git init --bare• git clone file://c:/data/shared/ourrepo.git (or)• git remote add origin file://

c:/data/shared/ourrepo.git• git push origin master• git remote -v

Page 42: Git One Day Training Notes

Pushing, Fetching, Pulling

• git pull• git fetch• git push• git push --tags• git log master..origin/master

Page 43: Git One Day Training Notes

Remote Branches

• git push origin mybranch• git push origin• git branch -r• git checkout -b mybranch

origin/mybranch

• git config --global push.default matching

• git config --global push.default simple

Page 44: Git One Day Training Notes

Deleting Remotes

• git branch -r • git push origin :mybranch• git push origin --delete mybranch• git remote prune

Page 45: Git One Day Training Notes

MODULE 4: MERGING AND REBASING

Page 46: Git One Day Training Notes

Back in the Day..

7ef7ab ef3ad2 22e4ff

ab4efa 6e3fd1

ee7ee7

Developer Branches for

an experimental

feature..

Merges his Changes back to the master

Page 47: Git One Day Training Notes

Enter The Rebase…

7ef7ab ef3ad2 22e4ff

fad3e1ab23d

6

ee7ee7

Page 48: Git One Day Training Notes

Warning!

• ONLY rebase on a local repo, never rewrite shared history

• If you’ve pushed your changes, live with it

• You can use git revert to develop compensating commits

Page 49: Git One Day Training Notes

Rebase Essentials

• git checkout mybranch• git rebase master• git checkout master• git merge mybranch

Page 50: Git One Day Training Notes

And when there are conflicts?

• git rebase --abort• git rebase --skip• git rebase --continue

Page 51: Git One Day Training Notes

Rewrite History with Rebase

• git rebase -i <parent-of-the-commit-to-start-from>

• (entries will appear from oldest to newest)

Page 52: Git One Day Training Notes

MODULE 5: OTHER RANDOM GITNESS

Stuff that doesn’t fit elsewhere…

Page 53: Git One Day Training Notes

Git Aliases

• git config --global alias.co checkout• git config --global alias.ll “log --

oneline –graph” • git config -l• git config --unset alias.ll

Page 54: Git One Day Training Notes

Soft and Hard Resets

• Provide a way of moving HEAD in your current branch

• Hard resets throw away working tree• Soft resets preserve working

7ef7ab ef3ad2 22e4ff ee7ee7

Normally HEAD would point to here

Page 55: Git One Day Training Notes

Deployment Options

• Create a bare repo on the shared drive and use file: protocol

• Host it on a shared Unix host and use the ssh: protocol

• Run a local git daemon!

Page 56: Git One Day Training Notes

Submodules

• git submodule add <your-git-submodule-repo>

• git submodule init• git submodule update

Page 57: Git One Day Training Notes

Git Revert

Page 58: Git One Day Training Notes

Git Bundle

Page 59: Git One Day Training Notes

MODULE 6: PUTTING IT ALL TOGETHER

Page 60: Git One Day Training Notes

Choosing a Team Workflow

1. Master is always golden (merge from CI/Dev branch)

2. Branch off master approaching release

3. Release Branch Centric4. <Your Strategy Here>

Page 61: Git One Day Training Notes

Git(hub) Flows

• Anything in master is deployable• To work on something new, create a

new named branch off master and push it remotely

• After signoff, merge it to master (via a Jenkins job!)

Page 62: Git One Day Training Notes

The Monster Exercise

Page 63: Git One Day Training Notes

MODULE 7: WHERE TO FROM HERE?

Now you know the basics…

Page 64: Git One Day Training Notes

Useful Books & Videos

Page 66: Git One Day Training Notes

Please Help Us Improve

• Please fill in a feedback card telling us how we can improve this experience

• We’d love a testimonial too

Page 67: Git One Day Training Notes

Thanks for Coming!

• Go forth and Git!