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.
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
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.