Version Control With Git
Version Control With Git
kr/p/6oP7x7
Version Control with Git
Why track/manage revisions?
Backup: Undo or refer to old stuff
http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging
Branch: Maintain old release while
working on new
http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging
Collaborate: Work in parallel with teammates
http://git-scm.com/book/en/Distributed-Git-Distributed-Workflows
Version Control Systems (VCSs)
Our focus
GitHub-User Perspective
You GitHub
Working Dir
Local Remote
Repos Repos
Let’s begin with an example…
You GitHub
Configure your Git client
(Rails Tutorial 1.3.1)
• Install Git
• Check config info:
$ git config --list
user.name=Scott Fleming
[email protected]
• Fix if necessary:
$ git config --global user.name "John Doe"
You GitHub
Remote
Repos
$ git clone https://github.com/sdflem/comp4081_demo.git
You GitHub
Working Dir
Local Remote
Repos Repos
$ rails new comp4081_demo
You GitHub
Working Dir
Local Remote
Repos Repos
$ cd comp4081_demo
$ git add -A
$ git commit –m "Created Rails project skeleton"
You GitHub
Working Dir
Local Remote
Repos Repos
$ git push
You GitHub
Working Dir
Local Remote
Repos Repos
Questions to answer
How organized?
You GitHub
Working Dir
Local Remote
Repos Repos
What operations?
How the repos is organized
http://git-scm.com/book/
How the repos is organized
http://git-scm.com/book/
How the repos is organized
http://git-scm.com/book/
How the repos is organized
Branch (last commit)
http://git-scm.com/book/
How commit works
Before
http://git-scm.com/book/
How commit works
After
http://git-scm.com/book/
Common Workflow
Last commit of
each branch
Organization with two branches
Currently checked
out branch
Common Workflow
Before
How git branch works
After
Common Workflow
Before
How git checkout works
After
Common Workflow
Before
How git commit works
with multiple branches
After
Common Workflow
Before
How git checkout works
After
Common Workflow
Before
How git pull works
After
Common Workflow
Before
How git merge works
e2b92
After
Common Workflow
e2b92
Before
How to delete branches
e2b92
After
Common Workflow
$ git push
e2b92
• 5 questions
• Update diagram in each
– Commit nodes
– Branch nodes
• Based on actions of Alice and Bob
– Collaborating via GitHub repo
Scott Fleming SF 1
Start like this
GitHub
master
11111
master Alice
11111
Bob
Question 1
• Alice:
– $ git clone https://github.com/whatever.git
– $ cd whatever
• Bob:
– $ git clone https://github.com/whatever.git
– $ cd whatever
• Alice:
– $ git branch myfix
– $ git checkout myfix
• (Alternatively)
– $ git checkout -b myfix
Question 3
• Alice:
– $ rails generate scaffold User …
– $ git add -A
– $ git commit -m "Added User" # 22222
• Bob:
– $ rails generate scaffold Micropost …
– $ git add -A
– $ git commit -m "Added Micropost" # 33333
Question 4
• Bob:
– git push
Question 5
• Alice:
– git pull
Appendix
What if…
master
33333
$ git checkout master
11111
$ git merge myfix
22222
myfix
$ git merge myfix
Auto-merging app/models/micropost.rb
Automatic merge failed; fix conflict and then commit result.
app/models/micropost.rb
class Micropost < ActiveRecord::Base
<<<<<<< HEAD
validates :content, length: { maximum: 140 }
=======
validates :content, length: { maximum: 120 }
>>>>>>> myfix
end
To resolve:
Manually fix the file; git add and commit