0

I was using git on Heroku, and everything was going very good. Now I am trying to use git on a VPS server, but I can't make it work.

I am doing it on terminal over ssh. It's a rails app. When I create a new rails app, I do git init git add . and a commit. On the server, I create a bare repo with git init --bare. It just fails when I try to push it.

Then I have tried to upload files to the server manually, create a repo there and clone it locally, but when I do changes locally, commit it and would upload them, it also fails.

I really did a few things more, trying to figure it out by myself what is failing. Got a lot of different errors and different ways of doing it... I read different tutorials, even my own server provider as one I followed and got errors.

When I got error messages, I've tried to find a solution, but I am not able in the end to make a push. Well, in some cases push goes well, but remote repo doesn't seems to change (and no errors after git push).

The last 48 hours I am literally just on the computer trying to make this work, everytime starting again and trying different things.

I think for once I was just one step from doing it right. Just realized after (and can't remember steps I followed) that it could be something with using different branches, because I made that and it looked a bit strange (for me):

$ git branch -r
origin/HEAD -> origin/master
origin/master

$ git branch
* master

Strange because I think maybe there aren't listed the same remote and local branches.

So my question is really how to start a new git repo with a blank rails app, and upload everything for the first time to my server. Don't know if it matters, but I use ssh to connect to the server from terminal, server as Apache/Phusion Passenger.

I have actually all google results about this marked as visited, even most of questions on here related to my problems. So hopefully someone can tell me the right way.

pzin
  • 4,200
  • 2
  • 28
  • 49

3 Answers3

1

Your steps seems to be good, nevertheless I'll provide them one more time

[user@server] cd path/to/repo
[user@server] git init --bare projekt
[user@home] git push user@server:path/to/repo --all
janisz
  • 6,292
  • 4
  • 37
  • 70
  • Thanks. Tried your push method and I get same as above, no errors, but no files on remote server. I realize that in both cases in the git folder they are created lot of files in **objects** folder. So I think I am doing it right. – pzin Mar 16 '13 at 19:45
  • Because "Bare repositories contain only the .git folder and no working copies of your files" more [here](http://www.saintsjd.com/2011/01/what-is-a-bare-git-repository/) so just init normal repo on server and push your changes as [adviced](http://stackoverflow.com/a/1764793/1387612) – janisz Mar 16 '13 at 21:43
1

It looks like you are very close. On your development machine ensure that you have the proper remote defined:

git remote add origin ssh://<username>@<hostname>[:<port>]/path/to/repo/dir

and then make sure your push includes the branch as:

git push origin master

You'll get something like:

ebg@ebg(21)$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 207 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To ssh://gozoner@<hostname>:2222/home/gozone/git/foo
 * [new branch]      master -> master

My exact process:

$ mkdir /tmp/foo; cd /tmp/foo; touch foo.c; git init;
$ git add .; git commit -m 'foo'
$ ssh remote
> mkdir ~/git/foo; cd ~/git/foo; git init --bare
> ^D
$ git remote add origin ssh://.../home/gozoner/git/foo
$ git push origin master

[edit]

If you then look in the remote repository, at ~/git/foo in my example above, you will only see .git like files. To get the repository contents, to run your rails app, do a clone.

$ ssh remote
> git clone ~/git/foo ~/rails/foo
> cd ~/rails/foo
> # your files are there; run web server
GoZoner
  • 67,920
  • 20
  • 95
  • 145
  • Thanks for your help. Well, I got there. Same messages (just some delta compression messages extra). But files aren't on the server. Doing a `ls` on remote machine (lets say on /home/newapp), I just get files such as branches, config, description, etc (seem to be the git files which I think they should be in something like /home/newapp/.git, but I wanted just follow your steps). – pzin Mar 16 '13 at 19:33
  • What you are seeing is actually correct for a `git init --bare`. The files aren't actually there; only the git contents. If you need the files, then do a clone. Note: I do the exact same thing. I have several rails developments - I keep a bare repository on my server host machine. On that host machine, I clone the repository and run a rails server from the clone. – GoZoner Mar 16 '13 at 20:08
  • Sorry if this questions are maybe to obvious (maybe I am too used to heroku's workflow with git): if I do a `git push` the files are not uploaded to the remote machine? Do I have to clone files any time I make a change/commit? And to get sure, to clone files to server I have to do `git clone user@server:path/to/railsapp`? – pzin Mar 16 '13 at 20:19
1

Not sure why it's not working for you, but here's a different way of setting up a remote repo.

(The following is based off of Chapter 4.2 of Pro Git. See the link for a more thorough explanation.)

Create a "bare" version of your repo. Run this command from the parent directory of your git repository.

local$ git clone --bare my_project my_project.git

Copy the bare repository to the remote server. This example puts the bare repo in ~user/git.

local$ scp -r my_project.git user@your-remote-server.com:git

Now it should be accessible from your existing repository by running this command from your local repo root:

local$ git remote add origin user@your-remote-server.com:git/my_project.git

or you can clone the whole thing:

local$ git clone user@your-remote-server.com:git/my_project.git
Rob Bajorek
  • 6,382
  • 7
  • 44
  • 51
  • Same results. The git files (my_project.git in your example) are all uploaded to the remote server very fine. But not the "real" files; the rails app files. The weird thing is that there are no errors messages, either with this method even not **GoZoner** nor **janisz** one. – pzin Mar 16 '13 at 19:58
  • You won't see "real" files in a bare repo. There are only stored as git objects. Effectively, a bare repo is the .git directory. If you try cloning the remote repo somewhere else locally (the last example in my answer), are your rails files there? – Rob Bajorek Mar 16 '13 at 22:43
  • Uhm.. So I was really doing it right, and everything was working, and it's just I have no idea for what git is it? Because no files and no running app on the remote server. :-/ Maybe too much info for my head right now. Very depressing. – pzin Mar 16 '13 at 23:02
  • Don't feel bad. If you've never worked with a bare repo directly, the difference between how it and a normal repo work isn't obvious. Glad you got it figured out, and good luck with your Rails projects. – Rob Bajorek Mar 16 '13 at 23:19