2

I have git installed on localhost as well as remote host with the same project folder.
So 1 repo on localhost and 1 on remote host both containing same files. What I want to do is use localhost files for development and then push them in the remote to update there as well.

How to go about it ?

David Ansermot
  • 6,052
  • 8
  • 47
  • 82
Prince Singh
  • 5,023
  • 5
  • 28
  • 32

1 Answers1

4

Simply add a remote to your local repo, and push to your remote host.

git remote add origin /url/remotehost/bare_repo
git push --all

For that, your remote host must have a way to be accessed by your local host through one of the supported protocols:

  • git daemon
  • shared folder
  • http(s)
  • ssh

And your remote host must have a bare repo, in order to be able to push to it.

On that bare repo, you can declare a post-receive hook which will checkout the received content in your remote host project folder.


The OP chose ssh (ssh://202.XXX.xx.xx:/path/to/repo.git), but had issue fetching/pushing.

cloning the remote repo is also not working its giving me error

 Bad port '' fatal: Could not read from remote repository.

I advised to specify the user which owns the repo on the remote server.
For instance 'git': git@202.XXX.xx.xx.
Then to try with and without the ':':

git@202.XXX.xx.xx:/path/to/repo.git 
# or 
git@202.XXX.xx.xx/path/to/repo.git

The sshd must be running. The port should be the default one (22).
One can check the sshd logs on the server side (/var/auth/log).

After all that, the Op reports the setup is working.


The post-receive hook must be put in the bare repo on the server, and be made executable:

cat > /path/to/bare/repo.git/hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/path/to/live/folder GIT_DIR=/path/to/bare/repo.git git checkout -f


chmod +x /path/to/bare/repo.git/hooks/post-receive
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250