Pages

Tuesday, November 19, 2013

Moving from svn to git :Step 1:Setting up Git on Windows, with TortoiseGit as UI


So, my department is planning on moving from svn to git for version management and we have been instructed to research git and see how it works for us. Spent the day installing Git on my personal laptop and playing with it. Here is my "Git novice" attempt at blogging about my experience.

Btw, I am installing Git on my Windows 8 laptop,

Installing Git

This could not get easier. All I had to do was to follow the steps given in the Git Getting Started Guide
Since I was using windows, I followed the guidebook instructions for windows. Steps were:
- Go https://msysgit.github.com and click on Downloads.
- I downloaded the latest version Git-1.8.4-preview20130916.exe

Ran the exe and the wizard walked me through the process, I left all the default selections intact and Voila!!!, I had git installed.


Here is what the sneaky installer had created the a folder called Git under program files,
here are the contents of the folder
Clicking on Git Bash opened up the Git Bash shell.

Now that I had Git on my laptop, I needed a repository I could work against. I probably could have used one of the gazillion repositories on GitHub, however I decided to create my own.

I signed up on GitHub and created a repository.

I started the git bash and  followed some of the steps mentioned in the First Time Setup chapter of the "Getting Started" guide. I setup the username and email to match the values in my GitHub account, just wanted to keep things simple for my first attempt.

I skipped the rest of the configuration mentioned in the guide.

Cloning the repository

For starters I decided to clone the repository mentioned in the Git Start Up guide

I brought  up the git bash, changed folders to C:\\work and ran

git clone git://github.com/schacon/grit.git

Within a blink of an eye a folder called grit was created under C:\\work
Here is how the git bash looked




And this is how the newly created directory looked:

So what just happened?

Apparently, .git has all the data for the repository pulled down, so that is now my local repository while the working copy is in the grit directory, all ready to roll.

Yay!!! That was simple. Now I was so eager to clone my very own repository. 

So followed the same pattern ie"
git clone git://github.com/<MyGitUserName>/<MyRepositoryName>

Ex: git://github.com/gsmsengupta/mysandbox

Before I knew the repository was downloaded and git was nice enough to let me know that the repository was empty. It was indeed empty. I needed to ato add something.

Adding and Commit files


I created a new file under C:\work\mysandbox and called it SandyBeach.txt

executing git status warned me of the un tracked file:

Next step adding the file to tracked status:

git add SandyBeach.txt

On running git status again, git let me know that a new tracked file has been added and that file has not been commited.

So I ran git commit.
As I had not set up my preferred editor in the 'Git Config' step, running git commit opened a VIM session, I entered some comments and saved the VIM. That completed the commit as shown below.


Push changes to remote repository


I wasn't done yet. I needed to push the changes to the remote repository that I had created on Git Hub.

Here is where I encountered my first road block.
As per the guide, I executed the following command:

git push origin master

However got presented with the following:

fatal: remote error:
  You can't push to git://github.com/gourijamenon/mysandbox.git
  Use https://github.com/gourijamenon/mysandbox.git

Here is a screen shot of the same:
What just happened here???
Did some research on the net and found out that github does not support push over git:// protocol.
So I had to use https as suggested.

The revised command was:

git push  https://github.com/gourijamenon/mysandbox.git

This now asked me for my GitHub username and password, and yay!!!! Pushed the file.



Though I had created a pretty useless text file, I could not be more proud. I had just commited it using git bash.

Installing TortoiseGit

Enough of bash commands, I was so ready for some UI click actions. I am pretty comfortable with TortoiseSVN so naturally gravitated towards TortoiseGit.

This again was very straightforward, visit site TortoiseGit download and install, piece of cake.
I was prompted to restart the laptop which I did. After restart, all my git repos now had the familiar green check and right clicking started giving me the TortoiseGit options. Check out the TortoiseGit website for details.

I added a few new files, right clicking prompted me to add. I could commit the files to the local repository. No problems till now.

I was ready to claim victory when I realized that I had not pushed the changes to GitHub.

So I right clicked and selected Push, here is what I saw:


I clicked OK and got the now familiar  You can't push to git:// use Https:// error



No problem I thought, I know exactly what to do, I need to change to Https protocol.

So I click on the Push, and click the manage button on the resulting screen:

That gave me an option to add the Https Option:

Ohhh...it requires a putty key, now where do I get that. Went back to research mode and came across two very helpful articles:
https://help.github.com/articles/generating-ssh-keys shows how to generate the ssh keys and add it to the repository.
http://olelynge.blogspot.com/2012/04/tortoisegit-and-ssh-keys.html gives step by step instructions on how to get tortoiseGit to use the key to  enable ssl.

So now that I had the Https thingie configured I selected that from remote destination dropdown and proudly clicked okay and guess what....TortoiseGit does not support Https, here is the screen shot of the spectacular crash and burn


Now what??? Dead End??? Not yet.... there is one more protocol I could try. SSH.

Went back to Manage Remote Destination and configured SSH.

URL was sshified as git@github.com:gourijamenon/mysandbox.git
I believe the for ssh access of github the URl pattern is:
git@github.com:<gitusername>/<yourgitrepo>


Here is a screen shot:



Went back, right click-->Push-->Selected remote destination configured to use SSH protocol.


Clicking on Okay prompted me for the key paraphrase:






After I entered the paraphrase...oh the sweet joy ........the changes were pushed to the remote repo.


No comments:

Post a Comment