git – SSD Nodes https://www.ssdnodes.com VPS Cloud Hosting For Hundreds Less Sun, 18 May 2025 19:53:09 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.1 https://www.ssdnodes.com/wp-content/uploads/2024/09/fav.svg git – SSD Nodes https://www.ssdnodes.com 32 32 Git Hooks — Easily deploy code via git push https://www.ssdnodes.com/blog/git-hooks-deploy/ https://www.ssdnodes.com/blog/git-hooks-deploy/#respond Thu, 08 Apr 2021 04:27:48 +0000 https://blog.ssdnodes.com/blog/?p=5802 The best way to get into any field is to start with a problem statement, and then learn the necessary concepts as you try and solve that problem. The same is true with DevOps and today we will start with a very simple problem and craft a very rudimentary solution for it.

Goal: Deploying code to remote server via git push

Let's say you have a website hosted on a VPS, and you have a local copy of its source code on your laptop. As your needs change, you will inevitably want to make some changes to the website. If you are using git to track changes to your source code, you can use another functionality of git called git hooks to push your local changes to the remote server, and have the server deploy it for you.

This is the crudest, and yet very effective way of getting started with DevOps. A practive which merges the Development workflow closely with that of Operations.

Prerequisites

To follow along this tutorial you will need:

  • A very basic familiarity with the Linux command line.
  • A very basic idea of how to use git, creating a repository and committing changes.
  • A VPS with a public IP for which you have key-based SSH access as root user.

Setting the stage

We will start with a very simple setup where an Nginx Server is serving plain HTML files on port 80 and we will make changes to these files locally and push the changes to the server running Nginx. If you follow along, by the end of the setup, just reloading the webpage at http://your_ip_address will show you all the changes that were pushed without you having to manually login into the server.

Local setup

To start with, you will need git installed on your local computer. Windows users should look at git-scm and if you are using Linux or WSL2 then you can install it via your package manager. Similarly, macOS users can install git via brew package manager or by simplying installing Xcode or Xcode Command Line Tools.

Great! Now that we have git installed, we create a simple git repo, and add some very simple HTML code in it.

$ mkdir html
$ git init
Initialized empty Git repository in C:/Users/r/html/.git/

Create a file in ~/html directory named index.html and add the following contents to it:

<!DOCTYPE html>
<html>
<head>
<title>Welcome to My Website!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to My Website.</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

Side Note

If you are using git for the first time. You will have to use git config --global user.name "your_name" and git config --global user.email "your@example.com" to set basic information that git uses to tag your commits.

Next commit those files into your repo:

$ git add index.html
$ git commit -m "Add index.html"

If you have used remote hosted git repositories such as those provided by GitLab, BitBucket or GitHub, you may have come across the git remote command. We will be using the same mechanism to push our files to the remote server. Just replace the your_ip_address part below with the actual IP Address (or FQDN) of your remote server.

$ git remote add production root@your_ip_address:/var/www/html.git

This tells git that we have a new remote endpoint for this repository called production located at /var/www/html.git on IP Address your_ip_address, and, to push to this repository as user root. Usually when pushing to GitHub or GitLab our remote is called origin, the user is git and the location is username/reponame.git.

But the remote endpoint does not exist yet. So, let's create that.

Remote Server Setup

The following is a one time setup for which you will have to SSH into your server. We will start by creating a bare directory for git repo. This is where all your git commits will be stored in a format that only git can understand, i.e, as a tree of commits and other objects. You don't have to know about its inner workings, just know that this where all the history of your repo lives.

$ cd /var/www
$ mkdir /var/www/html.git
$ cd /var/www/html.git
$ git init --bare

Next we will use another feature of git which are called git hooks. These are basically shell scripts that get executed when a certain action is performed inside the repository. In case of our production remote we will create a hook that publishes the updated contents of our repository /var/www/html.git to our webserver's root /var/www/html directory.

Inside /var/www/html.git directory you will find a hooks folder with a bunch of sample scripts. We will ignore these and create a new file with the exact name of post-receive.

$ cd /var/www/html.git/hooks

Create a file called post-receive in here with the following content inside it and save it.

#!/bin/sh

# Check out the files
git --work-tree=/var/www/html --git-dir=/var/www/html.git checkout -f

Next, we need to make the post-receive file executable.

$ chmod +x /var/www/html.git/hooks/post-receive

Install Nginx and if the html directory is not present, create it:

$ sudo apt install nginx -y 
$ mkdir -p /var/www/html

This is it for the remote setup. Let's take our setup for a spin!

Testing the workflow

If you've installed Nginx, then /var/www/html is the default root for that webserver, and its contents will be shown in the web browser as follows:

Nginx Default HTML Page

Now let's push our new HTML code from local setup:

$ git push production master

If you now reload the website, you will see that the title and the first heading have been revised to match our "custom" HTML file.

New Commit

 

This is it! You are now free to work on your local git repo and push changes with just a single command.

End Note

The post-receive script is just a general shell script. You can use this to reload nginx or MySQL or any other service as well as perform other actions that are required for more complicated apps running on NodeJS, PHP or the language of your choice. As your project grows you can add other remote servers for building, testing and much much more.

Finally, you should remember that while all the contents of your source code are pushed to the remote endpoint, the same isn't true for metadata like remote endpoints. If you were to push the repo to GitHub as well, you can do it, and they won't be able to see that you have an additional remote endpoint called production. Neither will the git hook script of post-receive ever leave your server. These are not part of the repository's contents.

]]>
https://www.ssdnodes.com/blog/git-hooks-deploy/feed/ 0
What Is GitHub & Why Do Developers Use It? An Introduction to GitHub https://www.ssdnodes.com/blog/what-is-github/ https://www.ssdnodes.com/blog/what-is-github/#respond Sat, 29 Aug 2020 10:49:44 +0000 https://blog.ssdnodes.com/blog/?p=5384 https://www.ssdnodes.com/blog/what-is-github/feed/ 0 Install GitLab On Your VPS To Host A Repository (Tutorial) https://www.ssdnodes.com/blog/install-gitlab-vps-ubuntu-debian-centos/ https://www.ssdnodes.com/blog/install-gitlab-vps-ubuntu-debian-centos/#respond Mon, 30 Sep 2019 09:00:00 +0000 http://ssdnodes.billabailey.com/2017/04/03/tutorial-setting-up-your-own-gitlab-repository/ Why install GitLab on your VPS?

GitLab is an open source application that offers a graphical user interface (GUI) to help manage Git repositories. It includes lots of features, such as issue tracking and easy pull requests and merges.

If you don't want to pay for GitHub’s or Bitbucket’s paid features, or if you want to maintain full control over your codebase, then a self-hosted GitLab installation is a great option.

Today, we'll walk you through how to install GitLab on your VPS running Ubuntu, Debian or CentOs.

Prerequisites for GitLab installation:

Step 1: Installing dependencies

To get ready to install GitLab on your VPS, you need to install some dependencies.

Luckily, they’re available in default repositories:

Ubuntu 16.04/18.04, Debian 8/9/10

$ sudo apt install curl openssh-server ca-certificates postfix

Centos 7

$ sudo yum install curl policycoreutils openssh-server openssh-clients
$ sudo systemctl enable sshd
$ sudo systemctl start sshd
$ sudo yum install postfix
$ sudo systemctl enable postfix
$ sudo systemctl start postfix
$ sudo firewall-cmd --permanent --add-service=http
$ sudo systemctl reload firewalld

Step 2: Installing GitLab on VPS

First, you need to add the GitLab repository, and then install the package.

Note: We recommend that you check all scripts you're executing as the sudo user before you execute them. You can find GitLab's install script here.

Ubuntu 16.04/18.04, Debian 8/9/10

$ curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

$ sudo apt install gitlab-ce

CentOS 7

$ curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

$ sudo yum install gitlab-ce

This operation might take a bit to complete.

When it’s done, you’ll see the following output:

*.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.

     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ 
  / /_/ / / /_/ /___/ /_/ / /_/ /
  ____/_/__/_____/__,_/_.___/

gitlab: Thank you for installing GitLab!
gitlab: To configure and start GitLab, RUN THE FOLLOWING COMMAND:

sudo gitlab-ctl reconfigure

Step 3: Run and configure GitLab

You've now installed GitLab on your VPS, so let's fire it up and make sure it’s running smoothly.

See that command above? Give it a whirl.

$ sudo gitlab-ctl reconfigure

You'll see quite a bit of output as the script operates.

If you need to make any changes to the external URL, for example, or any of the other configuration options, you can edit the gitlab.rb script and then re-run the configuration.

$ sudo nano /etc/gitlab/gitlab.rb
$ sudo gitlab-ctl reconfigure

IMPORTANT: If you followed our previous tutorial on installing a LEMP stack, you will need to configure GitLab to work with your existing nginx installation. GitLab has detailed instructions on how to configure the connection in their documentation.

Step 4: Log into GitLab for the first time

Once you’ve made any changes to GitLab’s configuration and it’s up and running without errors, you can direct your web browser to the default external URL, or the one you chose.

If you see the following page, you’ve successfully installed GitLab!

GitLab Success

Provide a password for the administrator account when prompted.

Then enter the password you choose, and then you’ll be directed to a login screen.

GitLab Login

The administrator username is root by default. Enter that plus the password you just created, and you’ll be ready to start managing your Git repositories directly on your own VPS!

 

]]>
https://www.ssdnodes.com/blog/install-gitlab-vps-ubuntu-debian-centos/feed/ 0
How to avoid Microsoft’s GitHub takeover https://www.ssdnodes.com/blog/microsoft-github-takeover-vps/ https://www.ssdnodes.com/blog/microsoft-github-takeover-vps/#respond Mon, 04 Jun 2018 20:50:04 +0000 https://blog.ssdnodes.com/blog/?p=2019 https://www.ssdnodes.com/blog/microsoft-github-takeover-vps/feed/ 0 Quick Tip: See yesterday’s Git progress at a glance https://www.ssdnodes.com/blog/git-stanup-progress/ https://www.ssdnodes.com/blog/git-stanup-progress/#respond Fri, 31 Mar 2017 00:00:00 +0000 http://ssdnodes.billabailey.com/2017/03/31/quick-tip-see-yesterdays-git-progress-at-a-glance/ https://www.ssdnodes.com/blog/git-stanup-progress/feed/ 0