49
now you git it! (part ii) PICSciE bootcamp 2019 by dev dabke ([email protected])

now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

now you git it! (part ii)PICSciE bootcamp 2019by dev dabke ([email protected])

Page 2: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

me

● he/him/his● education

○ applied math phd @ Princeton○ math/cs undergrad @ Duke

● industry○ AG350, Inc., other ventures○ ex-BlackRock, Airtable

● started with svn, then realized how git works and why it’s awesome

Page 3: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

1. introduction

Page 4: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

citation: xkcd and https://github.com/qw3rtman/git-fire

Page 5: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

workshop structure

1. overall stylea. feel free to jump in with questions at any time (don’t be afraid!)b. i will poll the audience a lot

2. today: a little theory and then mostly practical knowledgea. discuss some more advanced git conceptsb. practical examples as an individualc. working session as a teamd. more advanced tooling

3. high-levela. day 1: local, personal workflow; introduction to theoryb. day 2: remote, team workflow; more practical

Page 6: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

errata

1. git branch is a legitimate way to create branchesa. however: this only creates a branch, but does not immediately checkout to itb. usage: run git branch branch-name and then git checkout branch-name

2. git push --force should be avoided on shared resourcesa. sometimes useful if you’re the only one working on a branchb. necessary after a rebasec. be very careful with this

Page 7: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

centralized vs. decentralized

decentralized● everyone has the entire repo (yes,

submodules exist in git, etc., but c’mon)● checkout / checkin from anywhere● “canonical code” is established by

convention (`master` or `origin` aren’t special names in git)

centralized● one “master” repo● central server or machine hosts the

“canonical code”● checkout / checkin to one place● checkout only parts of a repo● easy to manage permissions

Page 8: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

mutable● possible to change history● history can be beautified, changed to be

easier to read for the future● more flexible● can be more dangerous

immutable vs. mutable

immutable● cannot rewrite the “history” or “record” of

what has happened● history reflects what actually happened● safer

Page 9: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

isn’t github a centralized system, though? wait . . . what is github?

Page 10: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

(aside: this is why we don’t use gitlab, although it is open-source)

Page 11: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

what is a commit?

Page 12: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

what is a branch?

Page 13: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

how do we reconcile differences between commits?

Page 14: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

recap

1. git is decentralized, mutable2. github (or equivalent) is a hosting service3. everything in git is an object, which has

a. contentb. pointer

4. branches are labels

Page 15: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

pop quiz: what is special about master?

Page 16: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

2. introduction

Page 17: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

repository

1. a folder that has been initialized by git2. contains

a. a working directory, i.e. what your filesystem seesb. a .git folder that maintains the version control information

Page 18: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

remote

1. location (or address) of a git repository2. can be on

a. your computerb. a local networkc. over the internet with

i. sshii. http(s)

3. composed ofa. a urlb. a name

Page 19: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

ref

1. unique way to identify a resource2. composed of a

a. remoteb. object identifier

Page 20: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

ref: HEAD

1. what current working directory is pointing at2. what is actually being changed upon checkout

Page 21: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

2. individual work

Page 22: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

preamble

1. setup a github accounta. associate and verify a personal email addressb. turn on two-factorc. associate and verify your princeton email if you have one; activate education account

2. ssh keysa. if you don’t have them:

https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

b. once you’ve created them or if you already have them: https://help.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account

Page 23: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

repository creation

1. create a new (public) repository on github2. initialize it with a readme file

Page 24: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

git clone

setup a local replica repository from a remote

Page 25: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

pop quiz: what is special about origin?

Page 26: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

git push

push a commit to a remote

Page 27: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

git fetch

check for changes in your local repository against a remote

Page 28: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

git pull

performs a fetch and merge at the same time (avoid this)

Page 29: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

local first, then remote

1. create a local repository2. then, create one on github

a. decline all automated configurations

3. push up your local repository

Page 30: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

3. team workflow

Page 31: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

preamble

1. pair up2. for each exercise

a. one person should create a repository with no default initializationb. add your teammate to your repositoryc. your teammate can now clone the repository

Page 32: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

general working principles

1. branches are cheapa. create personal working branchesb. even for collaborative work, create focused “feature” branchesc. be fearless: branch off of branches

2. keep master clean (so there is always one working version)3. stay in-sync with master

a. if ready, mergeb. otherwise rebase

4. first person to master winsa. the person merging into master is responsible for reconciling conflicts

5. fetch before you push

Page 33: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

ex. 1

1. create a README with each person’s namea. one person create README and commit to masterb. each person add a commit to their local master branch with their namec. reconcile the differences

Page 34: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

ex. 2

1. create a README with each person’s name2. each of you create your own file

a. use your own feature branchb. merge into master

Page 35: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

ex. 3

1. create a README with each person’s name2. each of you create your own file on your own feature branch3. collaborate on the feature branch

a. push up your feature branchb. the other person should modify your file on your feature branchc. pull in their changesd. merge the branch into master

Page 36: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

ex. 4

1. create a README with each person’s name2. each of you create your own file on your own feature branch3. initiate a pull request

a. push up your feature branchb. on github, click on pull request (pr) to masterc. once accepted, merge in through the UI

Page 37: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

ex. 5

1. create a README with each person’s name2. each of you create your own file on your own feature branch3. create secondary feature branches

a. other person shouldi. checkout and branch off of your feature branch

ii. make changes in their secondary feature branchiii. submit a “pr” to your feature branch

b. you should accept their prc. other person should merge their pr into your feature branch

4. finalize the feature brancha. make changes and submit a pr to masterb. merge in through command line

Page 38: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

fork

1. github concept2. replica of a repository but not integrated via git3. a way to handle permissions, since anyone with access to a repo can access the

whole thing

Page 39: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

ex. 6: massive fork experiment

1. fork my repository2. submit a pr by editing the README3. merge in changes

Page 40: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

wrap up

1. git is nota. a substitute for project managementb. a tool for communication

2. many ways to use git3. be courteous to your collaborators, strict with yourself

Page 41: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

4. advanced workflows

Page 42: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

project setup

1. gitignore2. README3. permissions

Page 43: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

hooks

1. scripts that active on events

Page 44: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

integrations

1. ci/cd2. communication3. project management

Page 45: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

1. “continuous integration, continuous delivery”a. ambitious b. broad

2. circlecia. integrate checks to githubb. “verifies” code

3. othersa. styleb. test coveragec. more?

ci/cd

Page 46: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

1. slack2. more?

communication

Page 47: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

1. github itself2. more?

project management

Page 48: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

references

https://git-scm.com/book/en/v2/

Page 49: now you git it! (part ii) · 1. git branch is a legitimate way to create branches a. however: this only creates a branch, but does not immediately checkout to it b. usage: run git

now you git it!