Let's build an app similar to the petitions app we built, now with the reddit API!
Sample Endpoint: http://www.reddit.com/r/funny.json
Documentation: http://www.reddit.com/dev/api
Code Solution: https://github.com/iExperience/reddit
A version control system is a tool to keep track of revisions you make to your files.
Some version control systems, such as Dropbox automatically keep revisions of every file you make.
What if we had some kind of time machine that allowed us to undo mistakes we make?
if student.going_skydiving?
store_moment :before_jump
end
# ...
if chute.failed? && student.screaming?
restore_moment :before_jump
end
That's what git allows us to do for code.
Git stores all of your code and each revision of your code in a repository.
Git is a source control manager (SCM), which is like a more powerful and complex Dropbox.
$ git init # initialize a new Git repo
$ git status # view current state of Git repo
$ git checkout # Undo local, unstaged changes
Deleting a file requires you to use git rm
.
If you don't, you can still use git add --all
so git can know that you deleted a file.
$ git rm <file> # Delete a file and track it
OR
$ rm <file>
$ git add --all # Will notice deleted files
Backs up your local git repository on the cloud.
Let's push some local projects onto GitHub!
Uh oh! Two people changed the same code.
<<<<<<<< HEAD
# this is my latest change
hobbit = Ringbearer.new(50, "Bilbo")
========
# this is the conflicted (existing) change
hobbit = Ringbearer.new(35, "Frodo")
>>>>>>>> Updated ringbearer to reflect modern history
Fixing merge conflicts is called resolving.
What does it mean if my changes were 'rejected'?
$ git push
To https://github.com/iExperience/iExperience.github.io.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/iExperience/iExperience.github.io.git'
Updates were rejected because the remote contains work
that you do not have locally. This is usually caused by another
repository pushing to the same ref. You may want to first integrate
the remote changes (e.g., 'git pull ...') before pushing again.
Someone else has made changes to the remote repository that you don't have yet.
$ git fetch
$ git merge
.
means current directory
fetch
and merge
before push
ing!