Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Ruby on Rails

Ruby on Rails Introduction


Introduction to Git
What is Git and how does it compare to other Version Control
Systems
Some good Git resources and references
Git is a VCS
Version Control Systems (VCS)
Def: System that keeps track of changes made to files
way to snapshot your code changes as you make them
Purpose: if things stop working, youre able to go back to the
last version where you know things used to work
Also known as SCM (Source Code Management) interchangeable
Centralized VCS
Eg. CVS, Subversion (old)
In the systems, the repository [code storage] resides in a
central server
Client has only 1 version of a trunk or branch, so if you need a
different version, you would either ask the essential server or you
could commit a new version yourself to the central server and
the central server will know the new
Git
Def: distributed version control system the full repository
resides locally on your system [not sitting on another server]
Repositories are distributed = every repository is its own unit,
which is readily available to be
The full repo resides locally
Each repository contains all the code and all the history of all
the commits
Contains full history
Full history resides locally on your system
Server is (almost) not involved
Commit often and offline commits goes on your local
storage system on your laptop
Work on the beach/train
Can push and pull between repos to sync up
Back ups trivial and readily available
Because every repository is its own unit and they are
distributed
Akin to VCS Mercurial
Git Basic
Only one .git directory at the top level (not sprinkled throughout
directory structure SVN)
General Workflow
1. (empty) Create or (existing) clone repo
Must have a repository
Clone 2 identical repositories one on laptop and one on
server contains the full history
2. Add changes to staging area
3. Commit changes (from staging area to local repo)
Interaction happens locally on your system
Commit commit locally committing to a central server
4. Push changes from local to remote repo
Snapshotting is happening on your system as youre
committing to your local repository way before you push your
changes to a mode repository
Push push remotely as opposed to the SVN you are
committing
Gits Official Site (git-scm.com)
Pro Git Free Git book (git-scm.com/book)
Good Git Reference (gitref.org)
Summary
Git lets you snapshot changes to your code
Promotes committing changes often
Quiz questions
What abbreviation is used to describe the function of
Git?
What are the advantages of Git being a Distributed
Version Control System?

Local Git Repository


Setting up your environment for Git
Interacting with your local Git repo
Git Setup
Setup properties globally
$git config --global user.name Luca AOMSTV
$git config global user.email gsnk1827@gmail.com
Verify that an option has been set
$git config <option>
in this case, $git config user.name
get the value that you put in
Get help on any Git command
$git help <command>
Initializing a Repo
Where do I get a repo from?
1. Create a new repo
$cd workding_dir
$git init
(possibly create a .gitignore file) temporary files you
don't want to add into the repository
$git add .
. = Adds the entire current directory with
subdirectories
$git commit m Initial commit gets files into the
repository
Cloning a Repository
2. Clone an existing repo (eg. From Github)
$git clone https://repourl.git
pull git hub repository into your local system
Many transfer protocols available
https:
git:
Git Status
$git status
Purpose: provides the current status of your repo
~/my_dir$ git status
On branch master
nothing to commit, working directory clean because you have
just committed no difference between your working and local git
repository
Branches on local, not only on remote
Git add
$git add <file/dir>
Add untracked file(s) to be tracked
Untracked files files that have never been tracked from a
repository area to a staging area
Add a modified tracked file to the staging area
Adds to the staging area [changes to be committed] if you
do a commit now, the file test.rb will go into the repository
1) changes to be committed staging area
- file test.rb will go into the staging area
2) changed not staged for commit = test is being modified, if you
do test commit, it will not go into your depository
() Mods made to the file after git add need to be git-
added again even if you did not commit yet
3) file is in this directory and has not been tracked
Git diff
$git diff
shows the difference between staging and working directory
$git diff --staged
shows the changes between HEAD (latest commit on current
branch) and staging directory
$git diff HEAD
shows the deltas between HEAD and working dir
git commit
$git commit
Commits your changes to the repo
Prompts for a commit message in an editor
Better, just use the m (message) option
$git commit m Your msg here
Skipping the Staging Area
To skip the staging area just use a flag
After initially adding the file
Either a, -m or am will do the trick
Only works if you are already tracking it
Do at least 1 git add
Going Back in Time
Before committing
$git checkout .
Re-checkout all tracked files overwriting local changes
$git checkout -- <file>
Re-checkout just one specific file
Overwrite 1 specific file
After committing
$git revert HEAD
reverts the most recent commit
right before you commit
Summary
You have to add a file for tracking at least once before it can make
it into the repo
Can easily go back in time to a snapshot

Remote Repos and Github


Interacting with remote repositories
Git hub
Remote Repos Set Up and Push
$git remote add alias remote_url
alias whatever you want to call it
link remote repo with your local repo
origin default alias for a cloned repo from a remote source
$git push alias branch_name
Push changes to your branch (master) out
$git push origin master
Github
Web-based Hosting service for software projects that use Git
Why use Github?
Community-oriented
Social networking functionality
Feeds, followers, watching projects
Interesting social networking graphs
Wiki, Issue tracking
Create issues on git hub and when you resolve the, you
can mark them as complete

Lesson 2
Ruby Basics
Ruby: High Level Overview
Dynamic
Object-oriented
Object-possessed, almost everything is an object
Elegant, expressive and declarative
Terse at times, but extremely readable
Influenced by Perl, Smalltalk, Eiffel and Lisp

You might also like