git for hackathons - kevinchen.co · download git os x install xcode windows install cygwin linux...

47
A Fast Introduction to Version Control --for-hackathons

Upload: others

Post on 07-Oct-2020

18 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

A Fast Introduction to Version Control

--for-hackathons

Page 2: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Who’s done this before?

http://thedailywtf.com/Comments/The_Best-est_Version_Control.aspx

Page 3: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

$$$ software does this!

Page 4: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

When projects get huge

Page 5: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

When projects get huge

Page 6: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Today, you’re going to see a better way of doing things.

Page 7: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Kevin Chen @kevinchen

Page 8: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Kevin Chen @kevinchen

Page 9: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Git organizes snapshots for you

Page 10: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

The Basics

Page 11: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Download GitOS X Install Xcode

Windows Install Cygwin

Linux Use your package manager

Page 12: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

git command options

Page 13: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Set up Git

git config --global user.name "Kevin Chen"

git config --global user.email "[email protected]"

git config --core.editor "nano"

Page 14: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Repository (“Repo”)A folder where Git is tracking changes

Page 15: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

cd my_project git init

Make a new repository

Page 16: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

CommitA snapshot of your repository

Page 17: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

CommitYou’re committing to the changes you made

Page 18: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Steps to Commitgit status (Which files changed?)

git diff (Which lines of code changed?)

git add my_program.c (I want this file in my next commit)

git add foo.c bar.c (Super fancy!)

git commit (OK, save a snapshot of what I just added)

git log (Show me the commit history)

Page 19: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Commit messages should have a concise summary.

Put it in the first line. 70 characters or less.

Page 20: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Commit messages should have a detailed explanation.

Skip a line. Wrap your text at 70 characters.

Page 21: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Fix a crash when taking pictures on Mondays !The function determine_photo_folder calculated the date index for Monday as -1, causing the statistics-tracking code to access invalid memory. The app will try to recover lost photos when users update to this version.

< 70 characters

Page 22: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

fuck this project, i hate programming

☹???

Page 23: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Fix a nasty race condition when analyzing multiple images !fuck this project, i hate programming

Page 24: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Demo: The Basics

Page 25: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

602925ce 9c5c3a97 f115369

Page 26: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

repository (“repo”) A folder where Git is tracking changes

commit a snapshot

Page 27: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Git as a safety net

Page 28: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

ResetYou messed something up and you want to go back.

Page 29: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

git checkout -- my_file.cRevert my_file.c to the last commit

Page 30: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

git reset --hard 61874b3Revert everything to the commit specified by 61874b3

Page 31: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

git reset --hardRevert everything to the most recent commit

Page 32: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

What if you wanted that code, but not at that moment?

Page 33: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

BranchingTrack separate versions of your code

Page 34: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

602925ce 9c5c3a97 f115369

Page 35: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Making a branch

git branch (List the branches of the repo)

git branch branch_name (Make a branch called branch_name)

git checkout branch_name (Switch to branch_name)

Now you can commit changes to that branch.

Page 36: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

602925ce 9c5c3a97 f115369

Page 37: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

602925ce 9c5c3a97 f115369 c5eb68a

9b41f5b b66e76b

64ba3bb

master

my_branch

Page 38: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Merging a branch

git checkout destination_br (Switch to the destination branch)

git merge other_br (Merge other_br into this branch)

git branch -D other_br (Delete other_br if you want)

Page 39: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Demo: Git as a safety net

Page 40: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Recap

Page 41: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

RECAP

Git helps you organize snapshots of your projects.

Page 42: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

RECAP

These snapshots are called commits.

Page 43: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

RECAP

If you mess up, you can always go back as long as there’s been a commit.

Page 44: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

RECAP

Branches let you try out new ideas without losing access to the version that works.

Page 45: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Additional Resources

gitimmersion.com (interactive tutorial)

git-scm.com (has a ridiculously detailed book on Git)

think-like-a-git.net (more advanced git)

Page 46: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

A Fast Introduction to Version Control

--for-hackathons

Page 47: Git for Hackathons - kevinchen.co · Download Git OS X Install Xcode Windows Install Cygwin Linux Use your package manager. git command options. Set up Git git config --global user.name

Twitter @kevinchen

Website kevinchen.co

I’m good at C/C++, Java, Git, servers, electronics, Photoshop

I’m OK with Web development, Ruby, Rails