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.
database.yml
# Ignore Rails documentation files
doc/
# Ignore Vim and Emacs swap files
*.swp
*~
.project
# Ignore (for OS X users) the .DS_Store directories created by the Mac Finder application
.DS_Store
.idea
.secret
Add the changes (recursively adding every sub-directory, too). <div class="os-specific"> <div class="nix">
git add .
</div> </div>
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: <div class="os-specific"> <div class="nix">
$ git commit -m "Initialize repository"
</div> 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. </div>
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 https://github.com/<username>/railsgirls-galway-2014.git
$ git push -u origin master