Version Control with Git

Created by Myriam Leggieri, @iammyr for Rails Girls Galway The basic guides that have been merged and adapted are the Ruby on Rails Tutorial, the basic RailsGirls app and the tutorials for creating thumbnails, authenticating users, adding design, deploying to OpenShift and adding comments.

Navigate to the root directory of the first app and initialize a new repository:

      $ git init

Before adding the project to the repository, let’s tell Git which files to ignore - because too frequently subject to changes - by listing them in the .gitignore file. The “rails new” command already create a .gitignore file but let’s extend it with the following.

# Ignore other unneeded files.
# Ignore Rails documentation files
# Ignore Vim and Emacs swap files
# Ignore (for OS X users) the .DS_Store directories created by the Mac Finder application

Add the changes (recursively adding every sub-directory, too).

git add . 

The “git add” command adds the project files to a staging area, which contains pending changes to your projectbu; you can see which files are in the staging area using the status command:

$ git status

Now commit the changes while justifying them with a message:

$ git commit -m "Initialize repository"
Git commits are local, recorded only on the machine on which the commits occur. You can view a list of all the commit messages with "git log" typing "q" to quit.

Now we want our changes to be pushed from our local machine to a remote repository. Create a repository called “railsgirls-galway-2014” and fill in the information. Do not to initialize the repository with a README file since “rails new” already created that automatically. Push up your local changes to the remote repository as follows:

$ git remote add origin<username>/railsgirls-galway-2014.git
$ git push -u origin master
The result is a page at GitHub (for instance, [here's mine]( for our application repository, which provides nice rendering, sharing functionalities and statistics: take a look by yourself at </div> **Coach:** Explain the branch-edit-commit-merge workflow on GitHub: modify the README file to be more descriptive. ([Slides by Myriam Leggieri @iammyr]())