Creating a new GIT repository
This tutorial will show you how to create a new GIT repository on your Site5 account. GIT is an alternative to Subversion (SVN) and is a great way to manage a code repository or project you’re working on. GIT is installed by default on all of our shared, reseller, VPS, and dedicated servers.
1. Login to your Site5 account via SSH (command line).
2. Let’s first create a folder inside of our home directory where we’ll keep all of our GIT repositories separate from our other files:
mkdir ~/git |
Note: The “git” directory is where we are going to store all of our repositories. For this tutorial, my test project will simply be called “project.” I’m going to walk you through setting up a fresh git repository on a blank project, but if you already have a project on your machine, now would be the time to upload it to the “git” directory we just created.
3. Let’s create a new GIT project:
cd ~/git; mkdir project.git; cd project.git |
4. Next, we will initialize our GIT repository:
git init |
After you run the above command, the output will look something like the below:
Initialized empty Git repository in /home/user/git/project.git/.git/ |
5. We can then add some sample files to our new project:
cd ~/git/project.git; touch test1; touch test2 |
echo "Site5 Is The Greatest" > test1; echo "testing" > test2 |
6. After we have added the test files, we need to “add” them to our repository:
git add test1 test2 |
7. Now we can “commit” the changes to our repository:
git commit -a -v |
The above command will open a new window in your default command-line text editor asking for a commit message. You can type whatever you want here.
8. After you commit your changes, you can check the status of the repository:
user@site5.com [~]# git status # On branch master nothing to commit (working directory clean) |
Eric Terrell February 19, 2012 at 10:40 am
Thanks for making git available to site5 users!
2 questions:
1) Once I set up a git repository on my Site5 server, can I manipulate the repository from another machine? For instance, can I do commits from my Windows computer? If so, what will the repository URL be?
2) I would like to have my website serve up the source code from the repository, without allowing users to make updates to the code. If this is possible, what URL would be used to browse the source code?
Thanks,
Eric Terrell
John Oliver at Site5 February 20, 2012 at 5:33 pm
1) You can access the repository from any machine you have SSH access on. The URL should be the same from computer to computer.
2) Take a look at the URL posted below. If you just need “read-only” access on your website, that link should work for you (just ignore the write access and Webdav part). You can just use .htaccess files for all of the allow/deny and password protection.
http://www.jedi.be/blog/2009/05/06/8-ways-to-share-your-git-repository/#apachehttp
I hope this helps!
Emilio Blanco February 25, 2012 at 5:41 pm
Hi!
Is there a way to have write access (push) from another PC?
Using something like git-http-backend and allowing me to configure users or groups(Like this article http://michael.otacoo.com/linux-2/creating-private-git-repositories-in-shared-hosting-environment/)
Thanks!
Emilio
John Oliver at Site5 February 27, 2012 at 12:35 pm
Hello Emilio,
You can push from any computer, so long as your login credentials are correct. However at this time, there is no way to do what that link describes on our services.
Michael Tyson February 29, 2012 at 9:45 am
Hey John – I was just wondering, is there any chance that a request to have git-http-backend installed might be granted?
John Oliver at Site5 February 29, 2012 at 10:21 am
Hello Michael,
Thank you for your comment. Because of the way our backend and security works, this is not something that we would allow. We do not allow daemons to be run by clients and the git-http-backend requires a daemon to work properly. You might be able to find a cgi or php script that runs without a daemon, but I am not aware of any at this point in time.
When our unmanaged VPS services are launched, you could do it there. More information about our new VPS services will be posted on our blog when the time comes.
Michael Tyson February 29, 2012 at 12:01 pm
Ahh, that’s a shame, but understandable – cheers, John!
Devon November 10, 2013 at 4:35 pm
” The URL should be the same from computer to computer.”
But.. the same as what?
AJ Michels April 16, 2012 at 6:34 pm
So I have been try to get all of this figured out. I am new to both Git and SSH. I have been able to establish an SSH connection using both Cygwin and PuTTY. I have also been able to create a repository on my hosted account. Where I am stuck is with actually using it. What I have gotten out of what you have already stated is that it is not possible for me to do “git commit http://git.myhost.com” from my local machine, and I think I understand the reason why. What I have tried to do is “git clone ssh://[email protected]” and it still doesn’t work. It asks me for my password, which I give it. And then it comes back and says “The server’s host key is not cached in the registry. You have no guarantee that the server is the computer you think it is.” I found this post http://stackoverflow.com/questions/4931384/git-server-host-key-not-cached and tried what he said but it still doesn’t work. And I have verified that the host/domain is in the known_hosts file.
What am I doing wrong. Or am I completely misunderstanding this and what I am trying to do is not possible at all.
Thanks for your help in advance.
John Oliver at Site5 April 17, 2012 at 12:50 pm
Hello AJ,
It sounds like there is not a key setup on the server, this could cause the error that you are seeing. You could try using the following article to create a key and then try using that key when you try to clone.
http://kb.site5.com/shell-access-ssh/how-to-generate-ssh-keys-and-connect-to-your-account-with-putty/
In addition, if you are using Windows, you may want to look into using something like gitolite or gitosis. That would allow you to use TortoiseGit on your windows machine to do all the hard work of managing your local repo. I have linked an article for gitolite below.
http://kb.site5.com/python/installing-and-setting-up-gitolite/
Please let us know if you have any other issues or questions.
Happy Hosting!
Josh Wilcox May 20, 2012 at 3:40 pm
I keep getting the following when trying to run git push origin master from my mac. I was able to clone the remote repo fine, add a new file and commit it, but I can’t push:
Joshs-iMac:scotch josh$ git push origin master
error: Cannot access URL http://git.joshuawilcox.net/scotch.git/.git/, return code 22
fatal: git-http-push failed
my ssh keys work fine, so I am not sure what the issue is.
Thanks!
John Oliver at Site5 May 21, 2012 at 3:29 pm
Unfortunately that is a generic error and can be hard to nail down the cause sometimes.
Could you try using the user/pass combo rather then your key to see if that lets you push?
Could you try using git:// and ssh:// for your URL prefix to see if either one works? Again I just want to test a few different things that may be causing this problem.
You may also be interested in something like the following:
http://kb.site5.com/python/installing-and-setting-up-gitosis/
Josh Wilcox May 25, 2012 at 3:20 pm
I’ll give that a whirl and see how is goes, Thanks for the resposne!
Josh Wilcox May 28, 2012 at 8:28 pm
Neither seem to working. When I try ssh://, it get “the directory scotch.git/.git does not appear to be a git directory, but that is the same directory that the clone checked out and it worked fine. when I try git:// it just times out and gives me:
fatal: unable to connect to ######@git.MYURL.net:
########@git.MYURL.net[0: MYIPADDRESS]: errno=Operation timed out
Mariano Cavallo August 23, 2012 at 1:46 am
Josh,
The .git directory inside your repo is not a repo itself it just contains all git objects and stuff.
Also, you cannot push via HTTP or GIT (unless theres a demon running, like in GitHub), for this kind of environment you want to stick with SSH for pulling and cloning (unless you wanna change your remotes manually every time you clone).
Try this:
git clone ssh://user@server/scotch.git
If you remote repo is set as bare please remember you need to specify the branch on your first push or it will fail:
git push origin master otherwise a simple git push will do
Hope this helps :)
Daniel Barbosa January 22, 2013 at 6:17 am
Hi!
I can I do a clone from my windows or linux pc?
I created a repository in http://git.myhost.com/test.git and if I try to clone it with “http://git.myhost.com/test.git” I get this error:
“fatal: http://git.myhost.com/test.git/info/refs?service=git-upload-pack not found: did you run git update-server-info on the server?”
If I try with “[email protected]/test.git” I get this error:
“fatal: repository ‘[email protected]/test.git’ does not exist”
What am I doing wrong? :(
John Oliver at Site5 January 24, 2013 at 5:33 pm
Hello Daniel,
This could be caused by a large number of things. Because of the nature of this error, I recommend that you open a ticket with our support team via Backstage so we can take a detailed look at your account.
Happy Hosting!
Devon November 10, 2013 at 1:08 pm
What should I do? Is this even the right URL?
git clone ssh://[email protected]/home/myusername/git/project
Cloning into ‘project’…
Connection closed by [IP]
fatal: The remote end hung up unexpectedly
I can ssh with putty.
project’s .git is at /home/myusername/git/project/.git
Devon November 10, 2013 at 8:50 pm
We worked it out:
the correct command would be
git clone [email protected]:/home/myusername/git/project.git
Alan Le August 14, 2014 at 6:26 pm
Thanks Devon, that syntax for cloning was really helpful. +1
Pavel October 10, 2015 at 12:49 am
Thanks for the guide! I am on shared hosting; is it possible/allowed to give a small number users access to this repository, as a sort of a private GitHub repository, without giving them general access to the site and domain management?
That is, I’d like to do something like what I can do with e-mail addresses: set up several USERNAMEs@MYDOMAIN, each with its own password and its privileges limited to pulling from and pushing to the git repository.
James Davey October 12, 2015 at 5:13 am
Hello Pavel,
Yes, you can allow access to remote users. They would simply need the name of your repository and the URL to use to connect. As for password protecting it, and setting up users for this, it would not be possible on a managed service.
Rich Peck February 2, 2016 at 4:49 pm
We just got this working, here’s what you have to do:
1) You should use SSH not HTTP
2) You should set up a bare repo on your server
3) If you commit your bare repo through SSH it will work
—
On sever:
– SSH into your account (Win 10 users can use powershell `ssh [email protected]`)
– `cd` into “deploy” directory (you need separate “deploy” and “public” dirs)
– run `git init –bare app.git`
On PC:
– Init `git` in your application root
– `git remote add site5 ssh://[email protected]/home5/[username]/path/to/app.git`
– `git add .`
– `git commit -a -m “Initial”`
– `git push site master`
On server:
– The repo should have been “pushed”
– You should add a `post-receive` hook to test if it works:
#home5/[username]/path/to/app.git/hooks/post-receive
#!/bin/sh
echo “Test”
—
If you push again, the “Test” message should appear.
Doing this will assure the system works, and you’ll be able to add to your `post-receive` hook to deploy the code to a “public” directory.
James Davey February 3, 2016 at 5:14 am
Hello Rich,
Thank you for the detailed steps explaining how you got this to work!
Nathan April 28, 2016 at 10:47 am
This method worked for me:
http://www.classy.dk/hacks/archives/004387.html