Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Version control is a git

Version control is a git

Frontend NE

July 06, 2017
Tweet

More Decks by Frontend NE

Other Decks in Technology

Transcript

  1. 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?!
  2. 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
  3. 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.
  4. — 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
  5. — The real word (me) KEEPING YOUR SHIT FILES BACKED

    UP ” “ WHAT IS VERSION CONTROL
  6. 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.
  7. 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
  8. 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
  9. 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
  10. 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 <div class="file-upload__link column column__12-of-12 column__6-of-12--medium"> <span>{{{ $field->value['url'] }}}</span> - <!-- <div class="button button--alt">Copy Link</div> --> + <div class="button button--alt file-upload__copy hide">Copy full link</div> </div> <a class="button button--auto-width file-upload__remove"> {{ Icon::inline('delete') }}<span>Remove File</span> GIT BASICS
  11. ADDING AND COMMITTING YOUR FILES (CONTINUED) git status On branch

    develop Changes to be committed: (use "git reset HEAD <file>..." 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 <file>..." to update what will be committed) (use "git checkout -- <file>..." 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
  12. 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
  13. 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.
  14. 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.
  15. 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.
  16. 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.
  17. 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
  18. 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.
  19. 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
  20. 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
  21. 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
  22. 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
  23. • 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.
  24. • 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.
  25. • 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.