Adding Source Control to Your Life

29
Adding Source Control to your Life Mark Kelnar 2013 Sunday, May 19, 13

Transcript of Adding Source Control to Your Life

Page 1: Adding Source Control to Your Life

Adding Source Control to your

Life

Mark Kelnar2013

Sunday, May 19, 13

Page 2: Adding Source Control to Your Life

Adding Source Control To Your Life

Who is this guy?

Mark KelnarWP Engine - lead developer@renderandserve github.com/markkelnar

Sunday, May 19, 13

Page 3: Adding Source Control to Your Life

HTMLJavaScriptCSSPHPJava, C/C++, PythonRuby on Rails, Perl, bashetc.

Adding Source Control To Your Life

Do you use any of these?

Sunday, May 19, 13

Page 4: Adding Source Control to Your Life

Adding Source Control To Your Life

Words worth rememberinginitclonecheckoutbranchfetchdiffcommitpullpushrevert

Sunday, May 19, 13

Page 5: Adding Source Control to Your Life

Coding without source control is like ...

Adding Source Control To Your Life

photographer Emily West (Courtney)

Sunday, May 19, 13

Page 6: Adding Source Control to Your Life

Pick a version control system

git, subversion (svn), cvs, mercurial, and many more

Adding Source Control To Your Life

Sunday, May 19, 13

Page 7: Adding Source Control to Your Life

What do I do with it?

Adding Source Control To Your Life

domain.comlaptop / dev

New header

Sidebar widget

Facebook feed importer

Work on different project/features, switch between them seamlessly, merge them together without missing anything

Sunday, May 19, 13

Page 8: Adding Source Control to Your Life

Adding github.com and staging branch

Adding Source Control To Your Life

laptop / dev

New header

Sidebar widget

Really cool facebook thingy

laptop / dev

github repopull requestsbranches

staging serverbranch testinggit pull

production serverbranchgit pull

pull/push

pull/push

pull

pull

Sunday, May 19, 13

Page 9: Adding Source Control to Your Life

Because you want to work with other smart people who can help.

Adding Source Control To Your Life

Sunday, May 19, 13

Page 10: Adding Source Control to Your Life

Create local repo

Adding Source Control To Your Life

Let’s talk about a simple example, local repo

http://git-scm.com/downloads

Sunday, May 19, 13

Page 11: Adding Source Control to Your Life

Create local repo

Adding Source Control To Your Life

Sunday, May 19, 13

Page 12: Adding Source Control to Your Life

Learn to branch

git checkout mastergit checkout -b some-new-feature<edit files>git statusgit diffgit commit -a -m ‘Edit theme for new cool feature’<another edit>git commit -a -m ‘Forgot the blue border’

Adding Source Control To Your Life

* Don’t commit it to production unless it’s ready to go live

Example:

Sunday, May 19, 13

Page 13: Adding Source Control to Your Life

Diff then Commit

Adding Source Control To Your Life

Sunday, May 19, 13

Page 14: Adding Source Control to Your Life

Merge branch back into main branch

Adding Source Control To Your Life

Sunday, May 19, 13

Page 15: Adding Source Control to Your Life

Adding Source Control To Your Life

Questions so far?

Sunday, May 19, 13

Page 16: Adding Source Control to Your Life

Push to remote using sshHere are two waysA) push to a bare repo on server then pull to another working non-bare repo Or B) push from local branch to a branch on non-bare repo then merge that branch into checked out / production branch.

B) Initial setupssh [email protected] /var/www/html/git init domain.com- at this point has no working branches, not even master. Only after initial push below

On local - one time, add remote server repogit branch laptop - create a local dev branchgit remote add theserver [email protected]:/var/www/html/domain.com/.gitgit remote show theservergit push theserver laptop

On server - one time, after initial push from local, set up working branchgit checkout laptopgit branch production

Adding Source Control To Your Life

Sunday, May 19, 13

Page 17: Adding Source Control to Your Life

Push to remote using sshB) Work flow after initial setup

On local - in dev branch ‘laptop’<edit files>git commit -am ‘changed code’git push theserver laptop

On server - when want changes to go live, merge the branch into working branchgit diff production laptop (show what is changing first)git merge laptop production (do the merge)

Adding Source Control To Your Life

Sunday, May 19, 13

Page 18: Adding Source Control to Your Life

Push to remote using ssh

How it get’s more complicated from there ...

add other humansadd testing environmentsadd staging environmentsadd customers with issues, darn those customers!fast iterations, push a lot, how to code review, test, etc

Adding Source Control To Your Life

Sunday, May 19, 13

Page 19: Adding Source Control to Your Life

Push local to github repo

github.com

Create account

Create repository

Adding Source Control To Your Life

Sunday, May 19, 13

Page 20: Adding Source Control to Your Life

Push local to github repo

github.com

Create account

Create repository

Adding Source Control To Your Life

Sunday, May 19, 13

Page 21: Adding Source Control to Your Life

Push local to github repo

Step 2ssh-keygen -r rsa -C "[email protected]"Add ssh key to github ssh keyshttps://help.github.com/articles/generating-ssh-keys

Step 3 - local devgit init domain.comcd domain.com<add files>git add .git commit -a -m 'Initial commit'

Adding Source Control To Your Life

Sunday, May 19, 13

Page 22: Adding Source Control to Your Life

Push local to github repoStep 4

git remote add github [email protected]:markkelnar/domain.com.gitgit remote show githubgit pull github mastergit push github master

Adding Source Control To Your Life

Example SSH repo locator

Sunday, May 19, 13

Page 23: Adding Source Control to Your Life

Pull from github repo

Step 5 (on the server, one time setup)

ssh-keygen -t rsa -C "[email protected]"cd /var/www/html/git init domain.comgit remote add github [email protected]:markkelnar/domain.com.gitgit remote show github

Step 6git pull github master

Adding Source Control To Your Life

Sunday, May 19, 13

Page 24: Adding Source Control to Your Life

Adding Source Control To Your Life

Questions so far?

Sunday, May 19, 13

Page 25: Adding Source Control to Your Life

*~

.svn

.cvs

.git

.listing

*.bak

*.swp

cache

.cache

temp

tmp

*.tmp

imagecache*

uploads*

*_backup

wp-config-sample.php

wp-content/w3tc*

wp-content/w3-*

wp-content/upgrade/*

wp-content/uploads

wp-content/blogs.dir/*/*

pclzip-*

log.txt

debug.log

gallery/*

wp-content/gallery/*

wp-content/album/*

wp-content/plugins/plugins

.htaccess ?

wp-config.php ?

Ignore some files

Adding Source Control To Your Life

Sunday, May 19, 13

Page 26: Adding Source Control to Your Life

Common Excuses (end...)

I heard it's hard.I’m a solo developer.I don't have money. I don't have time.

Adding Source Control To Your Life

Sunday, May 19, 13

Page 27: Adding Source Control to Your Life

If time for more time ...What about staging branches?

What about pull requests?

Adding Source Control To Your Life

featurebranches

stagingbranch production

branchbug fixes

pull request

pull request

Sunday, May 19, 13

Page 28: Adding Source Control to Your Life

Resources

Adding Source Control To Your Life

http://git-scm.com/downloads

https://help.github.com/articles/set-up-githttps://help.github.com/articles/generating-ssh-keys

http://code.google.com/p/tortoisegit/

Sunday, May 19, 13

Page 29: Adding Source Control to Your Life

Thanks!

Adding Source Control To Your Life

Sunday, May 19, 13