At PythonAnywhere we love github as much as the next person. It’s great! We use it for our main private repository and have a few public ones up there as well.
But sometimes you just want a private place to backup your little project to. And if you are like me you have about 30 little projects that are the software equivalent of napkin scribbling. Or maybe you think github is a little bit too cool. Maybe it’s trying too hard?
incidentally Git Fresh are PythonAnywhere’s favourite Miami based R&B-Hip-Hop like product
So sure you could just make those repos public but urgh. Not everything is public. Sometimes they are private to just you or sometimes you want to work on something with just a couple of other collaborators.
On PythonAnywhere with a premium account you can set up as many private repos as you want, as long as they fit within the diskspace limitations1, for $5 a month.
So, here’s how it works¶
PythonAnywhere has web based Bash consoles. We are going to use one of those to create a git repository. Then on your local machine we are going to clone it and make a commit. Then push that commit back up to your new private repo on PythonAnywhere.
The first thing you will need is a PythonAnywhere account. So go here and sign up for one and then come back.
Now visit your consoles tab and start a fresh Bash session.
Once inside you will be at a prompt that looks something like this and we can make our first remote repo
<username>@PythonAnywhere:~$ mkdir my_repo.git <username>@PythonAnywhere:~$ cd my_repo.git <username>@PythonAnywhere:~$ git init --bare
You can call your repo whatever you want. There is no potential for namespace collisions because everything is inside your own account.
Now, from your local machine you can clone that repo using
~/:$ git clone <username>@ssh.pythonanywhere.com:my_repo.git
If you haven’t added your public key to /home/
You can now add a file, make your first commit and push back to PythonAnywhere.
~/:$ cd my_repo ~/:$ touch README.md ~/:$ git add README.md ~/:$ git commit -m"Initial commit on my private PythonAnywhere repo" ~/:$ git push origin master
And that is it! Feel free to set up shared accounts to collaborate with others or work directly on your repo via our in browser editor.
Some additional tips and hints¶
Below are a couple more tips for people using PythonAnywhere as their git repository.
The git repo on PythonAnywhere is a bare repo. That means it has no working tree. You cannot work directly inside it. If you want to hack on your project directly from PythonAnywhere you will need to do a local clone. From a PythonAnywhere Bash console run,
<username>@PythonAnywhere:~$ git clone my_repo.git my_repo
Then do your work inside my_repo and push back to origin if you want to pull those changes outside PythonAnywhere.
Your PythonAnywhere git repos work over SSH. To enable pushing and pulling without having to enter passwords you can add your public key to your account. There are many ways to do this. But the following commands will work even if you have never created a Public/Private key pair before. If you have an existing key pair just skip the ssh-keygen part.
~/:$ ssh-keygen -t rsa ~/:$ ssh-copy-id <username>@ssh.pythonanywhere.com
People without the nifty ssh-copy-id utility can fall back to good old cat
~/:$ cat id_rsa.pub | ssh <username>@ssh.pythonanywhere.com "cat >> ~/.ssh/authorized_keys"
Where id_rsa.pub is whatever file contains the public part of your key.
Another way to make ssh access to a remote server easier is to put some settings into ~/.ssh/config.
My section for PythonAnywhere looks like this:
Host paw HostName ssh.pythonanywhere.com User hansel IdentityFile ~/.ssh/my_pythonanywhere.key
This means that if I want to connect to PythonAnywhere all I need to type is
~/:$ ssh paw
It even autocompletes :)
Another benefit is that I can clone one of my repos from PythonAnywhere with
~/:$ git clone paw:my_repo.git
Well, limited by disk space, but not quantity of repos, have a look at our account types for more info. ↩︎