(Advanced) Web Application Development More Git for Version Source Control Diagrams from http://git-scm.com/book Bruce Scharlau, University of Aberdeen, 2017
Bruce Scharlau, University of Aberdeen, 2017 Discuss with the person next to you why we want you to use Git for your work Bruce Scharlau, University of Aberdeen, 2017
Git provides a means for both: a global ‘what if’ as well as a global ‘undo’ in our projects Bruce Scharlau, University of Aberdeen, 2017
Where we’re going today Look at why we need version source control Look at how Git works for better understanding Try some ideas for better insight to Git Bruce Scharlau, University of Aberdeen, 2017
Bruce Scharlau, University of Aberdeen, 2017 Version control provides an undo for us so we can make changes with a safety net http://www.flickr.com/photos/daniandgeorge/8682531564/in/photolist-eeff95-8RRLk5-5UezrB-azM8yB-2L86u/ Bruce Scharlau, University of Aberdeen, 2017
There are many types of version control Some were local, others were server based, and some were distributed Git is a distributed version control system Git is used for growing number of projects including: linux, ruby and rails and many gems Bruce Scharlau, University of Aberdeen, 2017
Git tracks file changes Git is a version control system which tracks changes in files inside its repository As long as you’ve put the file into the repository tracking system, Git will know what’s been changed Bruce Scharlau, University of Aberdeen, 2017
Use one Git repository per project Create a new project in its own folder and then create a repository in the project git init git add . git commit –m ‘initial commit’ Bruce Scharlau, University of Aberdeen, 2017
Git tracks changes in files Git watches files and tracks the differences between different versions of files and stores those differences – hence it’s very lightweight and fast It only keeps the differences between versions Bruce Scharlau, University of Aberdeen, 2017
Git provides snapshots others Other systems track changes in files, eg subversion, CVS, etc Git Git stores data as snapshots, so a clone is the full backup of project Bruce Scharlau, University of Aberdeen, 2017
Git has three areas of operation Modified is changed, uncommitted file Committed means data is in repository Staged is modified file marked to go into commit snapshot Bruce Scharlau, University of Aberdeen, 2017
Four file status options Staged is what will be added to next commit Untracked is ignored Modified is changed, but not added to stage for commit Unmodified is unchanged Bruce Scharlau, University of Aberdeen, 2017
You can drop items from staging https://git-scm.com/book/en/v2/Git-Basics-Undoing-Things Remove from ‘staged’ with ‘reset’ and ‘checkout’ to discard changes NOTE: discarded changes are ‘lost’ and unrecoverable Bruce Scharlau, University of Aberdeen, 2017
Rolling back commit changes Use ‘reset’ to undo commits https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified has the details Hard and Soft resets move you back in commits Bruce Scharlau, University of Aberdeen, 2017
Tags let you refer to versions Git tag is a simple way to refer to previous commits Git tag is better than remembering/using the hash value of a commit Use ‘git tag <name>’ to create a tag And ‘git tag’ to list tags Bruce Scharlau, University of Aberdeen, 2017
Bruce Scharlau, University of Aberdeen, 2017 Demo the Git basics Show git tag, untracked, tracked, tracked and modified, and staged, plus committed and how to work with these Git immersion from labs 13->19 http://gitimmersion.com/lab_13.html GIT DEMO Show tagging versions,thenuntracked, tracked, tracked and modified, and staged, plus committed and how to work with these git tag <name>git checkout v1^ to get previous version checkout (HEAD^)change files in working dir with git checkout <filename>change file in stage and using git reset HEAD <filename> to remove file from stage and then us git checkout <filename> to be back where started create unwanted commit and then use 'git revert HEAD' to roll back, which pops you into editor.. save and close and back to where were can use 'git reset --hard <tag> to roll back to previous tag - not good in group projects though Can also do a lot more, but this gives basic idea Bruce Scharlau, University of Aberdeen, 2017
Git lets us try new ideas without messing up current work Bruce Scharlau, University of Aberdeen, 2017
Git lets you create branches A repository has a ‘master’ branch of the code and you can create more (just like a tree) for new parts – for example a new feature in the app Bruce Scharlau, University of Aberdeen, 2017
Branches are easy to toss away If you change your mind you can remove a branch – just like lopping off a tree branch Makes it easy to ‘try before you buy’ Bruce Scharlau, University of Aberdeen, 2017
We can also merge a branch to master If we do like the new code we can ‘merge’ it into the master branch of the code and thus drop the branch Bruce Scharlau, University of Aberdeen, 2017
Git works with remote repositories To ensure our code survives beyond our laptop with a remote repository. This removes the hassle of carefully copying the code to other locations via USB sticks, without overwriting versions. Bruce Scharlau, University of Aberdeen, 2017
Use ssh keys for remote repositories Remote repositories are checked using public and private keys instead of logins Git will have set one up for you when it was installed If not follow instructions at … http://git-scm.com/book/en/Git-on-the-Server-Generating-Your-SSH-Public-Key Bruce Scharlau, University of Aberdeen, 2017
Create private repos for your work You can use a private repos at Heroku (not just for Rails apps) Create account and then one repo per project to ensure you don’t loose anything Bruce Scharlau, University of Aberdeen, 2017
Use a repo for ALL coursework Github is payable for private projects, and free only for PUBLIC ones. Check if the Github ‘student’ account covers your needs Use Heroku or Bitbucket instead http://www.heroku.com/ https://bitbucket.org/ Bruce Scharlau, University of Aberdeen, 2017
Using public repos exposes you to plagiarism You are potentially guilty of plagiarism by using public repositories as others can copy your work. Use private repositories for coursework at Bitbucket or Heroku instead Bruce Scharlau, University of Aberdeen, 2017
Bruce Scharlau, University of Aberdeen, 2017 With remote repos you can collaborate on work: ‘undo’ things, ‘try ideas’ and ‘merge’ work Bruce Scharlau, University of Aberdeen, 2017
Collaborate with others via remote repo Remote repos mean we can share our work with collaborators and Git will keep track of who made which change Bruce Scharlau, University of Aberdeen, 2017
Using git in teams takes practice Individuals need to add steps in work when collaborating to avoid creating a mess of their projects Make the effort now to learn this and future group projects will flow much more smoothly Bruce Scharlau, University of Aberdeen, 2017
Teams need workflow method Discuss with the person next to you what workflow is needed with teams using version control Bruce Scharlau, University of Aberdeen, 2017
Local and remote need to be kept synced Teams need something like: Do your work, and then pull changes from remote, then run tests to see what’s broken, then fix code from changes team has made, then test again, then pull remote again to ensure up to date, Only then do you push when all tests pass Bruce Scharlau, University of Aberdeen, 2017
Local and remote need to be kept synced Do your work, and then pull changes from remote Only then do you push when all tests pass then run tests to see what’s broken then fix code from changes team has made, then test again then pull remote again to ensure up to date Bruce Scharlau, University of Aberdeen, 2017
Overlap of agile methods with git usage Team need to prioritise tasks in code, and decide who’s working on what so overlapping work is minimized Use Trello or Issues to track work/tasks https://trello.com/ Bruce Scharlau, University of Aberdeen, 2017
Go add Git to your projects Go back to your ongoing examples and create Git repositories inside each of them. Start using Git repos (both local & remote) for all of your work Bruce Scharlau, University of Aberdeen, 2017
We can deploy to remote sites like Heroku with Git Detailed instructions for use with Cloud 9 at https://www.railstutorial.org/book/beginning#sec-deploying References at https://devcenter.heroku.com/categories/ruby And example https://devcenter.heroku.com/articles/getting-started-with-rails5 Bruce Scharlau, University of Aberdeen, 2017
Why should we bother with Heroku? We can run large apps already on our own systems and C9 and Codio let us show these to others, so why bother with Heroku? Think about this yourself, and then discuss with the person next to you. Bruce Scharlau, University of Aberdeen, 2017
Install Heroku for your system $source<(curl -sL https://cdn.learnenough.com/heroku_install) For Cloud 9 and others download CLI from Heroku – detailed instructions to follow there Then use ‘heroku create’ to add heroku to a git repository and you can use this to deploy git push heroku master Bruce Scharlau, University of Aberdeen, 2017
Bruce Scharlau, University of Aberdeen, 2017 PG and Heroku for Linux Use these instructions for putting Postgresql in your Linux system https://old-homepages.abdn.ac.uk/b.scharlau/pages/blog/?p=361 Install Heroku from details here https://devcenter.heroku.com/articles/heroku-cli and in particular ‘other Linux options’ under ‘standalone installation’ which use the command $ curl https://cli-assets.heroku.com/install.sh | sh Bruce Scharlau, University of Aberdeen, 2017
Modify the Gemfile for Postgresql group :development, :test do gem 'sqlite3’ gem 'byebug', platform: :mri end group :production do gem 'pg' end Use special bundle install so that you don’t need Postygresql on your machine Optional flag $bundle install --without production Bruce Scharlau, University of Aberdeen, 2017
Don’t forget the extras Check Heroku details for more… viewing logs, using database, starting a console Heroku logs – tail (watch the app log) Heroku pg ( database details) Heroku run rake db:migrate https://devcenter.heroku.com/articles/getting-started-with-rails5 Bruce Scharlau, University of Aberdeen, 2017