Wednesday, August 22, 2012

Version Control of your Rails Application using Git

Creating and Configuring Git Repo

#Set your name for identifying the commits
git config  --global ""

#Set your email for correspondence during collaboration
git config  --global

#creating a shortcut "co" for checkout
git config --global checkout

#while we are inside our app directory, initializing a git repository
git init

#Adding all files in the current directory(.)
git add .

#Checking the status of the files under git repository. Since it's not committed yet, All of them woudl be visible
git status

#Committing the code with a message "Initial Commit" specified with -m flag
git commit -m "Initial commit"

#Now checking github status will give empty as everything is committed
git status

#Check the git log
git log

#Once the code has been commited, we can push it to Github for backup or collaboration
git remote add origin

#Push the code to remote origin added above as master branch
git push -u origin master

Branch, Merge, Delete and Push

#if you wanna edit something without affecting the original code, you create a branch
#This can be done using the following checkout "co" command with a flag -b and name of the branch
git co -b modify-README

#Check the list of branches with following command. It also shows which branch are we currently using with * before it
git branch

#Changing the extension of rdoc to md(Markdown Markup language), which github can understand and format neatly.
git mv README.rdoc

#Check ths status of the git repo now. We have one rename and one modification
git status

#We need not add the renamed file now. We have a flag -a which will take into account all modified including the renamed ones.(Not newly created)
git commit -a -m "Improved the README file"

#Now we have committed to a branch created. We'll switch back to our master with following command.
git co master

#Now merge the changes in the branch "modify-README"
git merge modify-README

#check the branches, we'll be currently on master(indicated by a * beside master)
git branch

#Since we are done with modifications and merged, you can abandon it or delete it using a -b flag as follows
git branch -d modify-README

#Now push the modified and committed code to github
git push


Post a Comment