Git: How to create a repository on a web server

David Nash bash, linux 0 Comments

I’m writing this mainly for my own reference. I found it very difficult to find instructions on using git for what I wanted.

The scenario: I have a web server (example.com), which I can ssh into. It has a website running on /var/www/website/. I want to create a git repo for it, and then from my development machine (devmachine) clone that repo, make changes, and when I’m happy push them to the web server.

I already have ssh keys installed so I can ssh from devmachine to example.com.

On both example.com and devmachine I have a user david who is in the group www-data.

Git on the server

First I need to create somewhere to store the project:

Okay, great! After creating the place to store it, I then went into the website directory and told it that the project is stored in my home directory. I then go back to my home directory and change the group permissions to www-data, so that I can push to it remotely, from devmachine.

Git on the development machine

I clone the repo I created, and then create a file called “test” to make sure I can push it to the server.

Back to the server

And there’s my test file, on the server! Now I can work locally, and when I’m ready push them to the server. I then ssh to the server and pull the changes to make them live.

Leave a Reply

Your email address will not be published. Required fields are marked *