Tuesday, November 11, 2008

How to Setup GIT on Windows and GITHUB

I am very excited to make a transition from Subversion to GIT.The development setup we have, 
Developers work on windows machines, and our main server where all Subversion repositories as well as Tomcat runs in on Ubuntu Linux.

The reason we moved to GIT, reasons unlimited
--inherent distributed nature, to have unlimited commits on local machine without connecting to server
-- create as many local branches you want,  watch a quick demo of Jeff Brown about GIT and grails to feel the power of local branches, http://www.g2one.com/quickcasts/grails-git.html.
-- very fast

Our new Setup will have, For now we are moving to GITHUB to host our repository , and developers will install GIT on windows using CYGWIN , and checkin their changes to local machines. Once they are ready, developers will push their changes to GITHUB for others to use it.

Here are the Steps
1. Install cygwin on developers windows machines
2. setup a account, and repositories on git hub
3. Push and pull code from github.

Step 1 :Install Cygwin on Windows

Set up Cygwin: http://www.cygwin.com/setup.exe

Note** When prompted for a package directory (this is the directory where all the packages of GIT and other cygwins will be stored, I had set this to c:\temp first time I installed it)

  1. Accept the defaults until you get to the "Select Packages" step.
    • In the "Devel" category, find "git: Fast Version Control System" and click once to select it. The word "Skip" should change to the latest version available: currently 1.5.2.2-1. (If you click more than once, you may see an earlier version, like 1.5.1.3-1. Click again until the latest version reappears.)
    • In addition, you can also select GIT-GUI (its a A Tcl/Tk based graphical user interface to Git.)
    • Also, select GITK (this gives a one more graphical tool to view your branches, history etc)
    • In the "Net" category, find "openssh" and click once to select it.
    • In the "Libs" category, select "tcltk".
    • In the "Editors" category, select "nano" or your favourite editor.
    • In the "Libs" category, select "subversion-perl" (only if you want to use git-svn).
  2. Click Next and the required packages will be downloaded and installed. It takes about five minutes.
  3. Check the option to add an icon to the Start menu.

After installation, you can access the shell using: Start -> Programs -> Cygwin -> Cygwin Bash Shell.

  • This plops you into a directory Cygwin calls "/home/username, which is available from Windows applications as C:\cygwin\home\username.
  • Your Windows C: drive is available from Cygwin under /cygdrive/c.
  • You can access your Windows "My Documents" directory with: cd /cygdrive/c/Documents*/username/My\ Docu*.

Run a few commands to configure Git:

   git config --global core.autocrlf true    git config --global core.editor /bin/nano    git config --global user.name "Your Name"    git config --global user.email your@email.dom    echo export EDITOR=/bin/nano >> ~/.bashrc    export EDITOR=/bin/nano   (Note , userNames will come from next step 2)

More information can be found on http://git.or.cz/gitwiki/CygwinBinaryInstall.
Here is the step by step process, with some modifcations..



Step 2 :Create an account on GITHUB 
--Create an account on GITHUB(its free for opensource projects) (www.github.com)
-- create a repository e.g say trial
-- Add names and email id of commiters in the GIT Hub pages
e.g say mark,  mark@harvestinfotech.com

Step 3 : Create a SAMPLE README file on developer machine 
git config --global user.email mark@harvestinfotech.com
git clone git@github.com:mark/trial.git (These two lines you should find in GITHUB)
mkdir trial
git init
touch README
git add README
git commit -m "first commit"
git remote add origin git@github.com:mark/trial.git

ADDING README TO GITHUB
so far, everything we have done is to the local machine, now we need to push this README file to github.
GIT uses highly secure way of Public keys to see who can add changes.
We need to generate Public keys of each developers machine and add those public keys to the github repository. This is a one time process.

Step 4 :  Generating the Public Key for each Developer  machine
  • Open the Bash Shell
  • Then create a ssh key by typing:
ssh-keygen -C “username@email.com” -t rsa
Then enter password/passphrase twice and when prompted for the name of file for the key leave blank and press enter

  • Look at the output and it will hint at where the key is stored. It’s stored in a .ssh folder somewhere, usually in your user folder c:\Documents and Settings\Username\.ssh on XP or c:\Users\Username\.ssh on Vista. The file with the public key is “id_rsa.pub”. Use windows search if you can’t find it. Then open it with notepad and copy the text.
  •  That is the public key you should add to your account on github. Leave the files where they are. Running ssh-keygen sets up the keys for both Git Bash and Git GUI that all come part of msysGit..
For more information on generating public keys for other OS, http://github.com/guides/providing-your-ssh-key

Step 5: Pushing the README to repository
In the bash shell, 
  git push origin master 

Awesome , you should now be able to see the README in the GITHUB repository.

Guys, let me know if we I missed anything.




1 comment:

Anonymous said...

neat git HOWTO. thanks for freshing my mind!