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?!
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
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.
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
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
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
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
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
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.
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.
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.
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.
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
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.
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
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.
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.
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.