Created
August 27, 2008 09:58
-
-
Save carlopecchia/7454 to your computer and use it in GitHub Desktop.
A git microtutorial by example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# start creating a new Rails application | |
rails silly_blog | |
cd silly_blog | |
# put it under version control with Git | |
git init | |
git add . | |
git commit -a -m "first commit" | |
# we are in "master" branch | |
git branch | |
# do some modifications (eg: add a new model) | |
ruby script/generate model Post title:string body:text | |
git add . | |
git commit -a -m "added post model" | |
# the log reflects alle the commits | |
git log | |
## Add an "experimental" feature | |
# make a new branch | |
git branch experimental | |
git checkout experimental | |
ruby script/generate model Rating value:integer post:references | |
git add . | |
git commit -a -m "added rating model" | |
git checkout master | |
# we are happy with these modifications, put them under the "master" branch | |
git merge experimental | |
# modify the "experimental" branch, without commit them | |
git checkout experimental | |
# modify the Rating model | |
cat "class Rating < ActiveRecord::Base; belongs_to :post; end" > app/models/rating.rb | |
git checkout master | |
git status | |
# moficiation tainted the "master" branch too | |
# go back into "experimental" branch and do a commit | |
git checkout experimental | |
git commit -a -m "now ratings belong to posts" | |
git checkout master | |
git status | |
grep "belongs_to" app/models/rating.rb | |
# modifications stay in "experimental" branch, | |
# to import it: | |
git merge experimental | |
## Conflicts management | |
# let's add a new file (TODO) into "master" branch | |
echo "#List of next actions to accomplish" > TODO | |
git add . | |
git commit -a -m "added a (empty) list of next actions" | |
git checkout experimental | |
# notice that the TODO file doesn't exists here | |
# let's import the most recent modifications | |
git pull . master | |
# let's add an action (in "experimental" branch) | |
echo "* write unit tests" >> TODO | |
git commit -a -m "added some action" | |
# let's add an action (in "master" branch) | |
git checkout master | |
echo "* buy milk" >> TODO | |
git commit -a -m "remember the milk" | |
# now the two version of TODO are in "conflict" | |
git checkout experimental | |
git pull . master | |
# during merging a conflict happens! | |
echo "# List of next actions to accomplish" > TODO | |
echo "" >> TODO | |
echo "* write unit test" >> TODO | |
echo "* buy milk" >> TODO | |
git commit -a -m "resolved conflicts on next things to accomplish" | |
git checkout master | |
git merge experimental | |
# now everything is aligned | |
## Let's housekeeping | |
cd .. | |
rm -fr silly_blog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment