I had occasion to do something pretty routine yesterday, push some python scripts into GitHub. It was only when I went to actually do it that I realized I interact with git and GitHub exclusively through the R Studio interface. I reasoned that it wouldn’t take long to do with python scripts pretty much what I do with R scripts…I was wrong. In the end it turned out to be really easy but it took me a while to figure out how easy it was.

Here’s what I set out to do:

1. I have a project called ‘operation-minty-hippo’ that I created on my laptop:
‘C:/Users/aaron.mamula/Desktop/operation-minty-hippo’. This project consists of a single python script that counts the number of times each word appears in an input document (blog post on the web, text file of a report, etc).

2. I want to push that project to a GitHub remote repository I created called “operation-minty-hippo”:

https://github.com/aaronmams/operation-minty-hippo.git

Possibly important details: my work laptop is running Windows 7 with git version 2.8.4.

Usually when I warehouse a project on GitHub I do this:

1. Login to my GitHub account and create a repository.
2. Open R Studio and create a new local project by cloning the github repo.
3. Create some scripts, commit them to the project, push the local project to the remote GitHub repo through R Studio.

Since, for obvious reasons, I don’t use R Studio when editing python code, my normal means of GitHubbing was not available to me. I decided to go through the command line and figured these steps seemed easy enough to follow.

Here is why they weren’t:

My laptop was not recognizing git commands. I have come to believe that this was an issue of adding the location of the git executable to my windows PATH environment variable. This presented an insurmountable problem to me as I was working on my government laptop and, having recently been striped of my administrative privileges, I could not amend ‘C:\Program Files (x86)\Git\cmd’ to my windows PATH variable without an administrative password (Ok, I realize that this is more of bureaucratic roadblock then a technical roadblock and hence my experience probably doesn’t generalize well but…whatevs).

The workaround turned out to be pretty simple: use the Git Bash Shell…this is a little less sexy then going full terminal…but just a little less sexy. Here are a few screen shots to illustrate the process in case anyone finds themselves in a similar predicament:

So it turns out that git installs with its own shell…probably old news to everyone else but super helpful for me in this case:

gitbash1

Once I had that shit open (windows start menu –> git –> git bash) it was a pretty simple matter of:

1. cd “C:\Users\aaron.mamula\Desktop\operation-minty-hippo
A. this switches the working directory over to where the local version of the project lives.

2. git init
A. creates a local git repository

3. git commit .
A. commit all the files in the local project to the repository
B. there are lots of options available here and I don’t know what most of them do. I generally just commit all my changes…maybe this is really bad practice. Perhaps some more experienced GitHubbers would like to opine.

4. git remote add origin https://github.com/aaronmams/operation-minty-hippo.git
A. link the local repository to the GitHub remote repository

5. git push origin master
A. push the files in the local repository up to the remote repository

gitbash2

This page was pretty helpful once I realized I could use the git bash shell instead of my windows command line.

Advertisements