When I’m at work, I’m behind a fairly strict firewall. Me and the firewall don’t really get along that well and we have a long, and troubled history. When I sit behind it, I see the web through a peep-hole of ports 80 and 443. Everything else is locked down, with explicit opening ssh or ppptp to specific remote IP addresses. Most of the time this is not a problem, but there are cases when such a setup can totally cramp your style.
For example, if you want to push some non-work-related code to Github on your lunch break. Since GitHub is not on the approved list of hosts our network team likes, there is no way for me to ssh to it. When I googled this problem, I have seen a lot of blog posts explaining how to get around this limitation by using ssh forwarding. Yes, this is a solution, but not a very graceful one. It would require me to run an ssh server on port 80 at my house, and bounce my data off of it. Either that or use a public http proxy, and a ssh over http tool like Corcscrew (which to me seemed a bit reckless).
So I assumed that this was one of those intractable problems that require much more effort to resolve, than I actually care to give. On the other hand, this seemed like a feature that was bound to get implemented one of these days. There had to be other people in the same predicament as me, and eventually GitHub would cave in, and implement a method to push and pull over HTTP or HTTPS. So I decided that “wait and see” was the best strategy here.
Of course about a minute after I tweeted the above, I realized that GitHub already implemented this feature. Back in April 2010. Which means for over a year now, I have been failing to realize the answer was right there under my nose. What is the secret? You have to use the right URL. You have to use this one:
Essentially what you need to do is to clone the repository like so:
git clone https://email@example.com/username/project.git
This will automatically set up your local repository to push via https rather than ssh. If you already have a local repository and you want to push it to a blank GitHub repository you can simply add a https remote master like this
git remote add master https://firstname.lastname@example.org/username/project.git
Or if you were using the standard method before, and would like to switch to https you can do it like this:
git remote set-url master https://email@example.com/username/project.git
Why am I writing about this now? Well, perhaps I want to add my voice to the cavalcade of links that Google displays when you search for “GitHub behind firewall”. There are probably other people out there like me that haven’t experienced the “duh” moment yet so this here post is to help them out.
Have you ever had a problem that you thought would take way to much effort to resolve when a simple solution was right there in your face? Let me know in the comments. Also to salvage this post for long time GitHub users who knew about this all along, and snickered while reading this, please share your favorite git tricks that git-newbs may not know, but should.