Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

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 user.name ""

#Set your email for correspondence during collaboration
git config  --global user.email xyz@gmail.com

#creating a shortcut "co" for checkout
git config --global alias.co 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 https://github.com/vamshi4001/first_app.git

#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 README.md

#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