A2 Hosting Git server SSH setup (A private Git repository)

Git SSH repository FAQ: How do I set up a private Git server on a remote ssh server, such as an A2 Hosting web server? (i.e., how do I create my own private SSH Git repository on an A2 Hosting server?)

I just created a new domain on an A2 Hosting web server, and one of the reasons I chose A2 is because they offer/allow Git hosting, specifically Git hosting over SSH.

If you’ve never set up a private Git repository over SSH, well, fear not, me either. But, I just got it done, and here’s how I did it.

A2 Hosting Git repository SSH setup

Here are the steps I just followed to create a Git repository, and then put that Git repository on my new A2 Hosting web server.

First, I created a test Git repository on my local computer:

$ mkdir foobar
$ cd foobar
$ git init

# add a couple of test files:

# note: if you have an existing project and want to tell git
# to ignore certain files and directories, create a '.gitignore'
# file in your working directory at this time.

$ git add .
$ git commit -m 'Initial commit'

Note: You may want to issue a git status command here, especially if you use the git add . command:

$ git status

You should see a message like this:

# On branch master
nothing to commit (working directory clean)

Move the local Git repository to your A2 Hosting (ssh) server

With this local Git repository set up, I began the process of moving the Git repository from my local computer to my new A2 Hosting web server.

First, I ssh’d into my web server, and then created a new directory on the web server:

$ mkdir gitrepo

Then, coming back to my local computer, I followed these steps to get my “foobar” Git repository onto my web server:

# i was in the 'foobar' directory, so move up one level
$ cd ..

# make a bare clone to create foobar.git
$ git clone --bare foobar foobar.git

# scp foobar.git to the web server. note the need to specify the
# ssh port with '-P'. (all names/addresses/ports changed):
$ scp -P port -r foobar.git username@hostname:/path/to/gitrepo

# note: foobar.git is a directory, so this scp command may
# result in a long list of output (one line of output per file),
# depending on the size of your project.

# foobar.git is now on the server. make sure i can clone it.
# first, move to some other directory:
$ cd /tmp

# now check the project back out of the git server (clone it),
# again specifying the SSH port:
$ git clone ssh://username@hostname:port/path/to/gitrepo/foobar.git

# you should now have a 'foobar' directory from the git server, and it
# will respond to commands like these:
$ cd foobar
$ git status
# On branch master
nothing to commit (working directory clean)

$ git remote

# if those commands worked as shown, congratulations, your project
# is now stored on your private git server.

Git hosting: How Git is like CVS (or, the need to do “git checkout”)

The initial process of working with a remote Git server seems to be a lot like working with a CVS server. In particular, you follow these steps:

  1. Create your initial project directory (like a CakePHP project dir).
  2. Do your initial config work in this directory.
  3. Do the "git clone bare" stuff shown above, and put the .git project file on your Git server.
  4. (Now this is where it gets to be like CVS.)
  5. Move out of your initial project directory.
  6. Move that directory to the side.
  7. Check your Git repo back out from your Git server.
  8. cd into the directory you just checked out.
  9. The server should be referred to as “origin”.

Everything should now work as described here, in the Pro Git book, and in my Git cheat sheet.

After you’ve done the git clone --bare work, here’s what these steps look like:

# assuming you're in your 'myproj' directory, move up one level
$ cd ..

# move that directory to the side (or delete it)
$ mv myproj myproj.orig

# clone your project back from the server (check it out)
$ git clone ssh://username@hostname:sshport/path/to/gitrepo/myproj.git

# this creates a directory named 'myproj'; cd back to it
$ cd myproj

# 'git remote' now shows the origin server properly
$ git remote

# use 'git remote -v' to see more information about the origin
# server
origin	ssh://username@hostname:sshport/path/to/gitrepo/myproj.git (fetch)
origin	ssh://username@hostname:sshport/path/to/gitrepo/myproj.git (push)

Again, if you’re familiar with setting up an initial CVS project (CVSROOT), these steps with git checkout steps will feel very familiar.

More A2 Hosting Git SSH server setup information

That's “all” it took to set up an A2 Hosting Git repository using SSH (a Git repository on an A2 Hosting web server over SSH). For more information on setting up a Git server, my best reference for this effort was the excellent online Pro Git book, specifically the Getting Git on a Server chapter.

I also had to run the man command on ssh, scp, and git commands to figure out how to handle the non-standard SSH port configuration that A2 Hosting uses. This Git man page also helped me get the SSH port syntax right, particularly the “Git URLs” section of that document.


cloning the repository is not necessary.

just do this:

git remote add origin ssh://username@hostname:port/path/to/gitrepo/foobar.git

should save you some valuable time


Thanks, just set up my hosting account on A2 Hosting today. This is just what I needed to get my Git repo up and running quickly.
Many Thanks!

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.