Version Control with Git

Rails developers as practically essential, namely, placing our application source code under version control. Version control systems allow us to track changes to our project’s code, collaborate more easily, and roll back any inadvertent errors (such as accidentally deleting files). Knowing how to use a version control system is a required skill for every software developer.

First-Time System Setup
After installing Git, you should perform a set of one-time setup steps. These are system setups, meaning you only have to do them once per computer:

$ git config --global user.name "Your Name"
$ git config --global user.email youremail@example.com

I also like to use co in place of the more verbose checkout command, which we can arrange as follows:


$ git config --global alias.co checkout


First-Time Repository Setup
Now we come to some steps that are necessary each time you create a new repository (which only happens once in this book, but is likely to happen again some day). First navigate to the root directory of the first app and initialize a new repository:


$ git init


Adding and Committing
Finally, we’ll add the files in your new Rails project to Git and then commit the results. You can add all the files (apart from those that match the ignore patterns in .gitignore)

 $ git add .


Here the dot ‘.’ represents the current directory, and Git is smart enough to add the files recursively, so it automatically includes all the subdirectories. This command adds the project files to a staging area, which contains pending changes to your project; you can see which files are in the staging area using the status command


$ git commit -m "Initial commit"

The -m flag lets you add a message for the commit; if you omit -m, Git will open the editor you set and have you enter the message there.It is important to note that Git commits are local, recorded only on the machine
on which the commits occur. This is in contrast to the popular open-source version control system called Subversion, in which a commit necessarily makes changes on a remote repository. Git divides a Subversion-style commit into its two logical pieces: local recording of the changes (git commit) and a push of the changes up to a remote repository (git push).

Comments

Post a Comment

Popular posts from this blog

Inserting and Moving elements inside Ruby Array

Interview Question on Ruby on Rails