Start with git SCM
If you already used SVN or SVK , give a try to Git, another source code management (scm) system.
I saw for weeks that many Rails/Ruby related projects, including Ruby on Rails framework itself, are hosted on Github, a git repository hosting.
You can begin with a free Github account (you have a repository with 100mo quota).
First install git on your desktop/laptop :
1) On a Mac Intel, you can install Git by Mac ports : First assure you have the latest release of XCode, then reinstall Darwin Ports. To install git launch the following command :
sudo port install git-core
2) You can also install Git manually :
cd /usr/local/src curl http://kernel.org/pub/software/scm/git/git-1.5.5.tar.gz > git-1.5.5.tar.gz tar -xvzf git-1.5.5.tar.gz cd git-1.5.5 make configure ./configure --prefix=/usr sudo make install
3) On a Fedora just launch the command :
# yum install git
4) On a Debian just launch the command :
# apt-get install git-core
Signup (choose username / password / email and add a public key) on Github.com… then create your repository (specify at least the project name).
Github gives you the following instructions to push your project.
On your desktop, create your project, then push it to the remote repository by launching the following commands :
mkdir <project name> cd <project name> git init touch README git add README git commit -m 'first commit' git remote add origin git@github.com:<github username>/<project name>.git git push origin master
Once this has been done , i copied the content of a Ruby on Rails application into my local repository, i committed the updates, then pushed everything to the remote repository:
cp -r ../<rails_app>/* . git add Rakefile git add app/ git add config/ git add db/ git add doc/ git add lib/ git add log/ git add public/ git add script/ git add test/ git add vendor/ git commit 'My project first import' git push origin master
Now the skeleton of my RoR application has been pushed to the Github repository.
Explanations : Git is quite different from Subversion , it’s a distributed SCM, which means you can work disconnected from the main repository (remote) by committing your changes locally.
The basic flow for the previous steps is the following :
The first time, you should create your git (local) repo (this create a .git in the root folder of your project):
# git init
Create a file for testing
# touch README
Then add it to your local repo :
# git add README
Commit to your local repo :
# git commit -m 'First commit'
Then we add the Github remote repository to our local repository as a remote server called “origin” (we say remote repo is “tracked”)
# git add remote origin git@github.com:<username>/<project name>.git
Push our changes to the remote repository, in the main branch “master” (being the equivalent of ‘trunk’ in Subversion) :
# git push origin master
Show the branches (-r : only remote branches; -a : all branches) :
# git branch -a * master
Suppose now another person (B) want to get a copy of (remote) repository :
# cd /path/to/my/workspace # git clone git@github.com:<username>/<project name>.git remote: Generating pack... remote: Done counting 359 objects. remote: Deltifying 359 objects... Indexing 359 objects...te: 100% (359/359) doneemote: e done remote: Total 359 (delta 94), reused 359 (delta 94) 100% (359/359) done Resolving 94 deltas... 100% (94/94) done # cd <project name>
Now this person (B) could update a file , then commit and push to the repository.
First do an update in a file from your project.
Show status :
# git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # # modified: README # no changes added to commit (use "git add" and/or "git commit -a")
Add the changes in your local repo :
# git add README # git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: README #
Commit this change to the local repo :
# git commit -a -m "Test update file" Created commit 23f0d7f: Test update file 1 files changed, 1 insertions(+), 0 deletions(-)
Then push these changes to the remote repo :
# git push origin master updating 'refs/heads/master' from 80749cfe5dde07cedc7e50be420a266d8b698232 to 23f0d7fa999d2f4d0cbaed550677c9d07f70b8ca Also local refs/remotes/origin/master Generating pack... Done counting 3 objects. Deltifying 3 objects... 100% (3/3) done Writing 3 objects... 100% (3/3) done Total 3 (delta 0), reused 0 (delta 0) refs/heads/master: 80749cfe5dde07cedc7e50be420a266d8b698232 -> 23f0d7fa999d2f4d0cbaed550677c9d07f70b8ca
Now the first person (A) should get its local mirror in sync with the remote repo : to do this, just launch the command :
# git pull Updating 80749cf..23f0d7f Fast forward README | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
We saw the mechanism of Push/Pull, working in the main “master” branch of the repository.
Further readings show you how to manage conflicts, work with other repository branches than “master”.
For Rails projects, you can use Capistrano for deployments combined with a Git SCM like Github.
Further readings :
May 13, 2008 at 9:31 am
Why do you link to a very old version of git? If someone is going to compile git for himself, at least link to the 1.5.5 versions
May 13, 2008 at 8:07 pm
4) On a Debian just launch the command :
# apt-get install git
would that not get you GNU interactive tools?
apt-get install git-core
is the right way to go