DEV Community

Elif Nur Turk
Elif Nur Turk

Posted on

How to Connect GitHub Repo to VPS Server

How to Connect GitHub Repo to VPS Server

Connecting your GitHub repository to a Virtual Private Server (VPS) allows you to deploy code, automate deployments, and maintain seamless updates. This article will guide you through the process, assuming you have basic knowledge of Linux, SSH, and Git.

Prerequisites

Before we begin, ensure you have the following:

  1. Access to your VPS

  2. A GitHub repository

  3. Git Installing and configuration

1. Access To Your Virtual private server (VPS)

To connect to your VPS, you’ll need to use an SSH (Secure Shell) client. One of the most popular SSH clients for Windows is PuTTY. This tool allows you to securely connect to your server and execute commands remotely. You can use any SSH/Telnet software.

Open the terminal and enter the domain URL.

Let’s launch the terminal to handle authentication.

After successfully verifying your username and password, navigate to the /www/var directory or the designated directory where the code will be installed. Use the appropriate command to access this directory.

cd /path/to/your/directory

Next, you can proceed to install Git within that directory.

sudo apt update
sudo apt install git
Enter fullscreen mode Exit fullscreen mode

Let’s verify that Git has been installed correctly without any issues.

git --version

Congratulations, your VPS server is now fully set up!

2. Get and Install the githup repository

Obtain the repository URL from GitHub to clone it onto your server machine.

Now, we can continue the cloning process from where we left off.

git clone git@github.com/username/repository.git
git init

Do not forget to add .env key incase you use it because it will not be auto installed. < This article > may help you.

If uyou already had a project file in directory but not installed with git you can run this command to connect project source to your github repo,

You can replace “main” with your own branch name

`git remote add origin https://github.com/your-username/your-repository.git
git pull origin main `
Enter fullscreen mode Exit fullscreen mode

Once the repository is cloned, navigate to the project directory and proceed with the initial build. Depending on your project’s setup, you may use one of the following commands to install dependencies, build and start the application.

Once you have cloned a repository, you can use git pull to retrieve and merge any new changes from the remote repository into your local copy directory.

You can replace “main” with your own branch name

`git pull origin main`
Enter fullscreen mode Exit fullscreen mode

Remember to rebuild your application and restart the VPS server every time you pull new changes from the repository. This ensures that your updates are applied correctly and your application is running the latest version.

By following these practices, you’ll maintain a robust and efficient development workflow, keeping your application up-to-date and running smoothly on your VPS.

Thank you for following along, and happy coding!

Top comments (0)