1

I have a server that I usually SSH into, to work on a website being hosted on that server's IP.

Working through SSH wasn't really efficient for me, especially because I am working with a collaborator, and it made it so that we couldn't work on a file at the same time.

So, I imported the files into my local machine, and connected it to a GitHub repo, and now both the collaborator and I work and push to that GitHub repository.

The website, however, is still hosted on that IP address, and I would like to be able to push the GitHub repository to the server, without having to ssh into the server every time and doing a pull.

Is there any way I can simply push either my local copy or the copy on GitHub to the server that I normally ssh to?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Zonova
  • 235
  • 2
  • 8
  • Why don't you want to ssh into the server? You could copy/push/rsync files from host to the server but that defeats the purpose of using a common git repo between two people – MrJLP Jun 07 '17 at 22:19
  • You could setup a git repo directly on the server. – MrJLP Jun 07 '17 at 22:24
  • I often make small edits to the code and want to see the effect immediately on the webpage, however, some of the code in it only works when run from the server (so I can't run it locally). Making a small edit and having to ssh in every time to do a pull and then opening the webpage is a bit of a hassle. Ideally, I'll be able to just push the changes to the server and refresh the webpage. – Zonova Jun 07 '17 at 23:21
  • You can use an authentication key for ssh login without password. It's nearly the same as being on the same host – MrJLP Jun 08 '17 at 00:04

1 Answers1

0

You could setup a git repo directly on the server

That would be the preferred approach:

On a remote SSH shell session, you can:

  • initiate a bare remote repository from your existing webserver folder
  • add a post-receive hook in order to updates your webserver folder every time a commit is pushed to it.

That way, you don't even depend on GitHub, but nothing prevent you to add a secondary remote to GitHub, for safekeeping purpose.

That is:

ssh me@remoteServer
cd /path/to/webserver
git init .
git add .
git status # add what you need to ignore to .gitignore
git commit -m "First import"
cd ..
git init --bare --shared webserver.git
cd webserver.git
git remote add origin ../webserver
git fetch
git branch main origin/main
git switch main
git restore -- .

Using git init --shared ensures your colleague can push to the same bare repository, as long as they are in the same Linux group as your account.

Add to your webserver.git/hooks a post-receive file (make sure it is executable: chmod 755), with:

git --work-tree=/path/to/webserver --git-dir=/path/to/webserver.git restore -- .
                                                   ^^^^^^^

Assuming you have a Git 2.23+, Q3 2019, or, if not:

git --work-tree=/path/to/webserver --git-dir=/path/to/webserver.git checkout -- .
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250