Deployment Git with a VPS

Deployment Git with a VPS

Git is a powerful version control system that allows developers to efficiently manage their code repositories and collaborate seamlessly with team members. In this step-by-step guide, we will walk you through the process of setting up and using Git in your VPS server in an easy and beginner-friendly way.

Installing and configuring git

  1. Connect to Your VPS Server First, log in to your VPS server using SSH.

     ssh your_username@your_server_ip
  2. Install Git: Most VPS servers come with Git pre-installed, but it's always good to verify. To install Git, use the package manager specific to your server's operating system.

     # on Ubuntu/Debian
     sudo apt-get update
     sudo apt-get install git
     #On CentOS/RHEL
     sudo yum install git
  3. Configure Git:

    Before you start using Git, you need to configure your identity. Replace the placeholders with your own name and email address:

     git config --global "Your Name"
     git config --global ""
  4. Check your configuration

     git config --list

    The git config –list command should return the configuration you added

Using Git Basic Command

  1. Create the Project Directory: First, create a directory for your project. You can do this using the mkdir command:

     mkdir project
  1. Create Files for the Project: Navigate into the project1 directory and create some files and a sub-directory:

     $ cd project
     $ touch file
  1. Initialize Git in the Project Directory: Next, you need to initialize a Git repository in the project1 directory using the git init command:

     git init

This command initializes an empty Git repository in the project directory, allowing Git to track changes in the files.

  1. Add Files to the Repository:

      git add .
  1. Make Your Initial Commit: After adding the files, it's time to make your initial commit. A commit is a snapshot of the changes you've made to the project. Each commit should have a meaningful commit message describing the changes.

     git commit -m "Initial Commit"

    The -m flag allows you to specify the commit message directly in the command. In this case, we use "Initial Commit" to indicate that this is the first commit for the project.

Adding SSH access to GitHub from your VPS

  1. Check if you already have an SSH key pair by running:

     ls -al ~/.ssh
  2. Generate SSH Key Pair on VPS: Log in to your VPS via SSH, open a terminal, and run the following command to generate an SSH key pair:

     ssh-keygen -t rsa -b 4096 -C ""
  3. View and Copy Public Key: After generating the keys, run the following command to display your public key:

     cat ~/.ssh/

    Copy the entire output of the command, which is your public key.

  4. Add Public Key to GitHub:

    1. Click on your profile picture in the upper right

    2. Select settings

    3. Click on SSH and GPG keys

    4. Click on the “Create SSH Key” button

    5. Give the key a “title” to help you identify it

    6. Paste the public key into the “key” field

    7. Save the key

  5. Test SSH Connection: To test if your SSH connection is working, run the following command in the terminal of your VPS:

     ssh -T

    You should see a message like "Hi username! You've successfully authenticated, but GitHub does not provide shell access."

  6. Update Git Configuration: To ensure Git uses SSH for pushing and pulling from GitHub, configure it to use the SSH URL. Run the following commands in your VPS terminal:

     git config --global ""
     git config --global "Your Name"
     git remote remote add origin

Now, your VPS should be set up to use SSH for interacting with your GitHub repository. Now , you can clone, push, and pull from GitHub using SSH without needing to enter your username and password each time.