#Git: The good, the bad and the ugly# ![picture of Ryan Tvenge](img/me.jpg) ###[@rtvenge](https://twitter.com/rtvenge) | [ryantvenge.com](http://ryantvenge.com/)###
# Git # ## better than a #HIMYM series finale ## ![HIMYM](img/himym.jpg)
![Git Logo](img/git.png) Git is an *open source*, *distributed* version control system designed for speed and efficiency
## The problems with **not** using version control ## * Overwriting or deleting a file can result in loosing history. * This problem is exasperated when working directly off a server. * Coding tends to "comment out" code as a form of rolling back changes. * Time wasted by trying to recreate an older version of a file.
# How is it different than CVS/SVN/P4? # * Free and Open Source * No network needed. * You can create a local repo without a remote repo. * Faster * The go-to version control system (thanks mostly to GitHub IMO).
## But the Wordpress theme/plugin repository uses Subversion! ## * You can use the [```git svn```](http://git-scm.com/book/en/Git-and-Other-Systems-Git-and-Subversion) command to push to a Subversion repository. * You can still use Git to track changes on your Wordpress sites.
# Git vs GitHub # * Git is the technology (version control system) that GitHub uses. * GitHub helps you host and share your repository. * Adds a Web interface to your remote repository. * Adds features like GitHub Issues, Forking, and Pull Requests.
# What does Git/Version Control do? #
## 1. History Tracking ## * What the change entailed * When the change happened * What was exactly changed ![repo screenshot](img/repo.png)
## 2. Collaboration ## * Distributed. Don't need to checkout files. * Who changed a file? When? Why? * Git breaks down not only on a per-file bases, but even per line. * So if 2 people make changes to the same file, Git is smart enough apply both changes ![repo screenshot](img/repo.png)
## 3. Rollback Capabilities ## * Can rollback a single file to a given commit * Can rollback the whole repo to a given commit
# Git Terms #
### Repository ### * aka repo * Refers to the project/folder that is under version control. * **Local Repository:** Lives on your computer * **Remote Repository:** Lives on a server somewhere * GitHub/BitBucket (Cheap and easy) * Beanstalk (expensive and easy) * Your own server (Cheap and robust, but not easy)
### Branches ### * By default, a repo has a "master" branch. * You can create more than one branch: * Master * QA * Staging * Production * But more times than not, you are just going to work out of "master".
## Git Tasks ## * **Commit** * taking file(s) and attaching a commit message explaining what was changed. * **Push** * taking code that is on your **local** repository and copying it to the **remote** repository. * **Pull** * taking code that is on the **remote** repository and copying it to the **local** repository.
## Git Tasks (cont) ## * **Clone** * Copying an existing remote repository * **Merge Conflict** * If Git can't figure out how to combine your code with another team member's, it asks you to clarify. * **Reset** * Rolls back a respiratory to a given time (aka commit).
## Simplest Setup via Command Line ## 1. Install [Git](http://git-scm.com/downloads) 2. Create Repo * ```$ cd /path/to/folder``` * ```$ git init``` 3. Commit and push * ```$ git commit -am "Changed wording of disclaimer."``` * ```$ git push```
## Creating remote repos ## * If using SourceTree, [Bitbucket](http://bitbucket.org) is the easiest solution (5 free private repos). * Create a repo on your own server (must have ability to install Git). * GitHub
## Using Git for deployment ## * Deploy to your own server (free): * [Digital Ocean Tutorial](https://www.digitalocean.com/community/articles/how-to-set-up-automatic-deployment-with-git-with-a-vps) * Beanstalk ($15/month) * [CSS Tricks Tutorial](http://css-tricks.com/video-screencasts/109-getting-off-ftp-and-onto-git-deployment-with-beanstalk/)
## Leveling up in Git ## 1. Create local repository. 2. Create remote repository for collaboration. 3. Deploy website via remote Git repository.
#Thank You!# * Twitter: [@rtvenge](https://twitter.com/rtvenge) * website: [ryantvenge.com](http://ryantvenge.com/) * GitHub: [rtvenge](http://github.com/rtvenge/)