user2502380
user2502380

Reputation: 13

Git Workflow: Local to server

So I started developing something locally and turned it into a git repo. Then I took the folder and ftp'd it onto a server. Now I have SSH access to the server and git is installed. I cd'd into the folder and git said there wasn't a repo there, which I thought was stored in /.git/ and would have been uploaded with it.

I'm basically looking to add this server as a remote to be able to push to but now I'm not sure if it's setup right. Would the correct way be to clone from local first? How do you do that?

Also git config --get remote.origin.url isn't giving me anything on the server. I feel like I'm missing a big piece of the puzzle here.

Upvotes: 0

Views: 143

Answers (1)

janos
janos

Reputation: 124648

The repo on the server should be a "bare" repository. Do it like this:

  1. ssh to the server and create a bare git repo:

    git init --bare /path/to/repos/project.git
    
  2. On your local PC, add a remote like this:

    git remote add origin ssh://[email protected]/absolute/path/to/repos/project.git
    
  3. And push to the remote for the first time:

    git push -u origin master
    

Notes:

  • "origin" is just a common name for the main remote, you could name it anything you want, and replace that in both commands above.
  • When you give the url of the remote, the path component must be absolute path on the server. For example if the repository is in your home directory, then it will look something like ssh://[email protected]/home/user/path/to/repos/project.git.

Upvotes: 1

Related Questions