Slide 1

Slide 1 text

VERSION CONTROL IS A ‘GIT’

Slide 2

Slide 2 text

A BIT ABOUT ME • I’m @Chrisdkemper • Occasionally seen with a beard • Potentially in some kind of nerdy t-shirt • Getting close to 10 years in the industry • I’ve written a couple of books (one of them was on version control) • I'm (figuratively) shitting myself, have you seen this room?!

Slide 3

Slide 3 text

BOOKS AND THINGS • Version Control For Web Developers was written back in 2014 • One dude didn’t like it • One guy did like • Was written when I was primarily using SVN

Slide 4

Slide 4 text

THINGS HAVE CHANGED MORE RECENTLY THOUGH • I no longer have to use SVN • Been using GIT for personal and professional projects for years • Still wearing the nerdy t-shirts.

Slide 5

Slide 5 text

PUT YOUR HANDS UP IN THE AIR

Slide 6

Slide 6 text

— Wikipedia REVISION CONTROL, ALSO KNOWN AS VERSION CONTROL AND SOURCE CONTROL (AND AN ASPECT OF SOFTWARE CONFIGURATION MANAGEMENT), IS THE MANAGEMENT OF CHANGES TO DOCUMENTS, COMPUTER PROGRAMS, LARGE WEB SITES, AND OTHER COLLECTIONS OF INFORMATION. ” “ WHAT IS VERSION CONTROL

Slide 7

Slide 7 text

— The real word (me) KEEPING YOUR SHIT FILES BACKED UP ” “ WHAT IS VERSION CONTROL

Slide 8

Slide 8 text

MY SHIT IS TOTALLY FINE WHY SHOULD I CARE ABOUT VERSION CONTROL? • In short, because it saves your ass. • If you work with code, you’ll need to use it eventually. • Employers love it • You can show off what you’ve done via a public repo on Github or Bitbucket.

Slide 9

Slide 9 text

WHAT IT IS GIT, WTAF?! • Git is one of a few distributed version control systems • Initially created by Linus Torvalds in 2005 to make managing the linux kernel easier. • Widely supported with online hosting services (GitHub, Bitbucket etc) What about the name though? - random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of "get" may or may not be relevant. - stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang. - "global information tracker": you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room. - "g*dd*mn idiotic truckload of sh*t": when it breaks

Slide 10

Slide 10 text

CREATING A NEW REPOSITORY AND CLONING ONE • git init is your friend • a .gitignore file can make your life a lot easier • Initialized empty Git repository in /Users/chris/htdocs/ testfolder/.git/ • You can do git init in an empty folder or one with existing files, it doesn’t care. • Until you do your first commit, your files aren’t versioned. • When you clone down a repo, it’ll track the remote repository as origin by default • git clone [email protected]:chrisdkemper/ chrisdkemper.github.io.git GIT BASICS

Slide 11

Slide 11 text

ADDING AND COMMITTING YOUR FILES • Make good friends with git status • When doing git add on a file (or files), it stages them to be committed, but doesn’t commit them • If you change your mind about a file, or all of them, git reset has your back • You can add all of the things by using git add . • git reset --hard HEAD will reset all your changes back to how they were GIT BASICS

Slide 12

Slide 12 text

ADDING AND COMMITTING YOUR FILES (DIFFING) git diff app/views/item/fields/file.blade.php diff --git a/app/views/item/fields/file.blade.php b/app/views/item/ fields/file.blade.php index bcd4c08..92532ae 100644 --- a/app/views/item/fields/file.blade.php +++ b/app/views/item/fields/file.blade.php @@ -13,7 +13,7 @@ @endif {{ Icon::inline('delete') }}Remove File GIT BASICS

Slide 13

Slide 13 text

ADDING AND COMMITTING YOUR FILES (CONTINUED) git status On branch develop Changes to be committed: (use "git reset HEAD ..." to unstage) modified: app/routes.php modified: app/views/includes/pending-delete.blade.php new file: app/views/item/deleted.blade.php modified: src/SuperCleverStuff/Cms/Controller/ItemController.php Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: app/views/field/list.blade.php modified: app/views/item/fields/file.blade.php modified: app/views/item/list.blade.php modified: app/views/module/list.blade.php GIT BASICS

Slide 14

Slide 14 text

ADDING AND COMMITTING YOUR FILES (CONTINUED) • When you’re ready to make a new version git commit -m “Commit message” and you’re set. git commit -m "Reordered some fields” [develop ea69915] Reordered some fields 1 file changed, 5 insertions(+), 16 deletions(-) GIT BASICS

Slide 15

Slide 15 text

DELETING FILES GIT BASICS • You can either delete the file yourself (if git already knows about it) via Terminal or whatever means and it’ll be marked as `deleted` by git status Then you just need to git rm the file and git will forget about it. • if you want git to forget about the file, but not actually delete it, then git rm [filename] --cached is what you need. • Deleting a directory and it’s contents? Don’t forget to use -r to flag it as recursive.

Slide 16

Slide 16 text

BRANCHING GIT BASICS • Branching is your friend, and will make your life a lot easier • git branch [branchname] will create a branch but not check it out • git checkout -b [branchname] will create a new branch and check it out • git branch -d [branchname] to delete nicely (Will boot off if unmerged) • git branch -D [branchname] will force delete a branch • You can merge branches by using git merge [branch] which will merge the specified branch into the current one.

Slide 17

Slide 17 text

CHECKING OUT GIT BASICS • The checkout command can be used for switching branches e.g. git checkout master or git checkout feature/awesome- feature • You can also checkout the most recent version of a file by using git checkout [filename] • If you have a conflict, using git checkout --ours or git checkout --theirs can come in very handy.

Slide 18

Slide 18 text

PUSHING AND PULLING GIT BASICS • If you’re collaborating with others, odds are you’ll both be working at same time. • If you try and push and you need to pull, you’ll get an error • Normally though, git push [origin] [branch] (git push origin master) will push the changes you’ve been working, but be sure you’re on the correct branch! • Pulling is just as easy, git pull [origin] [branch] will get any remote changes that are available and all being well, there’s no conflicts.

Slide 19

Slide 19 text

CONFLICT MANAGEMENT GIT BASICS • With great collaboration, comes great conflict potential. From github.com:chrisdkemper/PHPNE-Silex * branch master -> FETCH_HEAD Auto-merging filename.c CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result. • There are diff tools available to handle conflicts, but I personally find it easier doing it in the file <<<<<<< HEAD ======= Some changes here >>>>>>> develop

Slide 20

Slide 20 text

CONFLICT MANAGEMENT (CONTINUED) GIT BASICS • If a conflict exists, you won’t be able to commit or do any other actions until it’s resolved. • After it has been resolved, you can just add it, and then commit to resolve the conflict. • git checkout --ours or git checkout --theirs can be of use as well.

Slide 21

Slide 21 text

LOGGING GIT BASICS • Although git log is pretty cool, but itself it’s quite hard to read. • Something like git log --pretty=oneline will make things a bit cleaner

Slide 22

Slide 22 text

STASHING GIT BASICS • Being able to temporarily “stash” your changes comes in so damn handy • Very useful when you need to pull down changes but you don’t want to commit yet • git stash, git stash list and git stash apply are the commands you’ll need to make the magic happen • git stash apply stashid can come in pretty handy if you double stash

Slide 23

Slide 23 text

SOMETIMES, PEOPLE READ THEM COMMIT MESSAGES • Although it’s tempting to just smash the keyboard for a commit message, if you need to come back to the code, you’ll not be helping yourself • whatthecommit.com

Slide 24

Slide 24 text

THERE’S GUIS TOO IT’S NOT ALL COMMAND LINE Some cool applications are: - SourceTree - Tower - Github for Mac/Windows <3 - TortoiseGit (Windiz) There's loads, honest. http://git-scm.com/download/gui

Slide 25

Slide 25 text

“REAL WORLD” EXAMPLES

Slide 26

Slide 26 text

I DON’T WANT TO ADD THE WHOLE FILE

Slide 27

Slide 27 text

• git add -p [filename] is the best! • You get full control over the file, and can decide to stage “hunks” of the file, rather than the whole thing. • You can also just run git add -p and run it on every file you’ve modified.

Slide 28

Slide 28 text

WHOOPS, I MISSED A FILE ON THAT COMMIT/THAT COMMIT MESSAGE SUCKS

Slide 29

Slide 29 text

• git commit --amend can come in very useful! • If you want to add additional files to the previous (unpushed) commit, then you can run git add and then git commit -- amend to add the newly added files to the commit.

Slide 30

Slide 30 text

“GO BACK AND ADD TICKET NUMBERS TO YOUR COMMITS”

Slide 31

Slide 31 text

• When it comes to making changes to multiple commits, then git rebase (in interactive mode) is your friend. • git rebase -i HEAD~X (X being the number of commits) will allow you to pick which commits to keep/modify. • git rebase is very powerful and you can do a lot with it, certainly worth looking up.

Slide 32

Slide 32 text

No content