Working with GIT

March 12, 2010 | 2 Comments

We were an SVN Fan over CVS for the fact that it was so simple to use until we found Git which was faster and much powerful. Git allows faster version control in a distributed development environment. It has full fledged repository and efficient tracking capabilities. Branching, Merging or Cloning; any activity was smooth, fast and reliable.

Most of our development work is done on Moodle. So we chose Moodle repository to clone and play with.

To install git on our linux servers

#yum install git-core gitk

To Create a git repository create the folders

#mkdir /git
#cd /git/
#mkdir moodle.git
#cd moodle.git/

Lets Initialize a blank repository

#git init --bare --shared=group

Fetch Moodle versions – The same command be run in cron to update at an hourly basis

#git --bare fetch git://git.moodle.org/moodle.git cvshead:cvshead#git --bare fetch git://git.moodle.org/moodle.git MOODLE_19_STABLE:MOODLE_19_STABLE

Make a working copy


#cd /var/www/html/
#git clone file:///git/moodle.git moodlegit
Initialized empty Git repository in /var/www/html/moodlegit/.git/
remote: Counting objects: 354671, done.
remote: Compressing objects: 100% (89253/89253), done.
remote: Total 354671 (delta 261661), reused 352647 (delta 259667)
Receiving objects: 100% (354671/354671), 144.86 MiB | 8.50 MiB/s, done.
Resolving deltas: 100% (261661/261661), done.
warning: remote HEAD refers to nonexistent ref, unable to checkout.

I got an error and check out fails — Warning: Remote HEAD refers to nonexistent ref, unable to checkout. Which means it tries to setup a tracking branch that is not there in your local repository.


#cd moodle19git/#git branch -r ---- When i used this command it showed me two hidden directories for cvshead and MOODLE_19_STABLE

You can do away with this warning by issuing command #git branch master which in this case will be the command below. This will switch it to the master branch.


#git branch cvshead

Now I checked out the two branches


#git checkout -b MOODLE_19_STABLE origin/MOODLE_19_STABLE#git checkout -b cvshead origin/cvshead

Next I created a new branch for edvanta for customizing moodle 1.9+ for a project


#git checkout -b mdl19-edvanta origin/MOODLE_19_STABLE

Now we can any changes on this. and then push it back to the server so that other developers can use it.


#git push origin mdl19-edvanta:mdl19-edvanta

Now others can take my code and work with it on their system locally like this


#git clone file:///git/moodle.git moodlegit
#cd moodlegit
#git checkout -b mdl19-edvanta origin/md19-edvanta

Once they have made their changes they can chose to publish their work to the main repository.


#git add
#git commit -a -m "Changes made by the third party developer"
#git push origin/mdl19-edvanta mdl19-edvanta

To export to moodle2 directory without .git folders

#git checkout-index -a -f --prefix=/var/www/html/moodle2/


Comments

2 Comments so far

  1. Siddharth on March 13, 2010 1:54 am

    Thanks for sharing this! It was a big help.

  2. Adrian on March 13, 2010 1:58 am

    I have been using SVN as my central repository for development. We knew svn works well with Trac. But the power Git brings serving as a distributed version repository along with Trac is commendable. I wanted to make the switch and now I think I will

Name (required)

Email (required)

Website

Speak your mind