Thursday, August 8, 2013

Setting Up My Google Project and git in Windows

I decided to use Google Code Project Hosting for my source code repository and git as the Source Control Manager (SCM).

Why?

Well, I'm doing this Blogger thing in Google, so might as well put the code on Google, too.


git was one of a few choices for SCM on Google Code Project Hosting.  SubVersion was another, and I have used SubVersion before... am familiar with it, yet I picked git.  I just did.


The thing about git, is it is really a unix/linux thingy, and I am developing on a Windows machine right now.    Seems that when you install the git client, it installs a bash terminal, so you kind of end up using whateverNIX anyway.  Might end up on Linux since Raspberry Pi is in my Dartboard Hack design.  No big deal for me since I've been on a whateverNIX system a few times before.


So, after you create a new project and repository, you need to create a local repository on your development machine.  Here's partly what I did and partly what I should have did if i had did it right the first time.


On Google Code, I created my new project named  "no-arms-darts," selected git as the SCM and went to the "Source" tab.


On my development (windows) system, I created a "git" folder in my Documents folder.  Then I installed the git client for windows and ran the git bash app from the link conveniently created in the start menu by the installer.  I changed the directory to my new git folder:


$ cd ~/Documents/git


Then I set git up to connect to my repository on Google code.  Looking back to my project source page on Google code, it gives the following option to do this:


Option 2: Stay authenticated with .netrc:
Add the following to your .netrc.
machine code.google.com login [Me@Gmail.com] password [generated googlecode.com password]

To use .netrc, make sure the clone URL doesn't contain your username:
git clone https://code.google.com/p/no-arms-darts/


To do this on windows, .netrc is actually _netrc.  So I clicked the link to generate my googlecode.com password and copied it to my clipboard.  Then I opened a command prompt in windows and:


C:\Users\Me> echo machine code.google.com login [Me@Gmail.com] password [generated password] > %HOMEPATH%\_netrc


Where [Me@Gmail.com] is my Gmail account and [generated password] is the password generated by the link on my Source code page under Option 2 shown above.


Then I went back to the git bash and executed the clone command, also shown above under option 2:


$ clone https://code.google.com/p/no-arms-darts


You would substitute your project name in place of no-arms-darts to clone your project... (or you can execute this for my project to clone all of my crappy code onto your development system).  This should create a new folder with the same name as your project under the git folder.


Since I already had some code for my project elsewhere on my system under a folder named "Python", I went to Windows explorer and copied the Python folder to the clipboard, then pasted it into C:\Users\Me\Documents\git\no-arms-darts.

Most of the time when you are developing with source control, there are files and directories used for developing, testing, debugging, etc that you don't want to be saved in the shared repository.  git has several ways to handle this ...like per repository, or globally.  I added a .gitignore file that I found on github among many prefab ignore files for specific development platforms.  This will effectively exclude the pycache folders, compiled scripts and so forth.


I just browsed my project and think I put the ignore file in the wrong place... looks like it is working out in its current location, but maybe should be at the root or master folder of the repository.


The next thing to do was copy all the files to my google code repository which took 6ish steps: add the Pyhton folder and its files to the local repository, set my email address and user name for the git config, commit the changes, set the default push mode, push the changes.... all done in the git bash, from the no-arms-darts folder:


$ cd no-arms-darts

$ git add Python



$ git config --global user.email "Me@Gmail.com"


$ git config --global user.name "Me"


$ git commit

git config --global push.default simple
$ git push


Now, the commit command opens up a whateverNIX text editor which I know as vi, and it prepopulates a commit document with comments detailing the files being committed, adds, mods, deletes... and requests that you add a version comment, and I think if you don't, it cancels the commit.  If you don't know how to use vi, you might want to try a git GUI or learn some vi commands. Quick and dirty:  press i to insert the comment, type the comment, press Esc to exit insert mode, then :wq to write your changes to the file and quit vi.

Oh, ok.  I actually read some of the git documentation and you can avoid the whole text editor thing by using the -m switch on the commit command like:

$ git commit -m "fixed another stupid mistake (rtfm)"


As I implied earlier, I didn't do this right the first time through... so I became acquainted with a few more git commands along the way: status and reset.  These are all explained very well in the git documentation.


After pushing the code to google, I went back to my source browser and the code was there.  If you are reading this and decide to look at this code, it's probably not the highest quality Python code... hopefully I will clean it up so it's actually worth looking at.  Maybe I'll run through this all again and take some screen shots and rewrite this post to make it more like a tutorial than a memoir.

No comments:

Post a Comment