Skip to content

Git Online

By now, you hopefully have at least a basic idea of what Git is, and how important a tool it is for Djangonauts. In this chapter, we will explore Git-based distributed version control systems in the cloud. We will mostly focus on GitLab, but also briefly look at another popular alternative, GitHub.

GitLab

GitLab is a web-based platform that offers a free and open-source solution for source code management. It provides a comprehensive set of features for developers to collaborate on projects, including version control, issue tracking, and continuous integration and deployment (CI/CD). It is very developer-focused, and popular among some of the largest companies.

GitLab uses a freemium model, so it can be used for free with some more advanced features restricted to Premium and Ultimate tiers. It is open-source, and can be hosted locally, but self-hosting is outside the scope of this book.

In this chapter, we'll start by signing up to the GitLab platform, and uploading a project to it. Later in this book, we will use the online repository to deploy the application, and learn about the powerful CI/CD tools.

Signing up to GitLab

To sign up to GitLab, follow these steps:

  • Go to the GitLab website and click on "Sign in".
  • On the login page, click "Register now".
  • Fill out the registration form with your details, or choose one of the alternate methods like registering with your Google account.
  • Click on "Create Account" to complete the sign-up process.

Adding your SSH key

In order to push our code to GitLab, or access private repositories, we need to add our SSH key to our account. If you do not yet have an SSH key, please create one as described in the Intro to SSH chapter.

Accessing SSH key settings

Find your SSH key by running cat ~/.ssh/id_ed25519.pub, copy the value, then go GitLab, click your avatar on the top left of the page, and select "Preferences". Once there, you will need to visit the section titled "SSH Keys", and click the "Add new key" button.

Paste the key into the "Key" field, and give it a descriptive title to identify which machine it is for. At the very least, the key should be used for Authentication, but you can leave the usage type set to "Authentication and signing". You may delete the expiration date if you wish; by default, keys are valid for one year.

Creating a project

To create a new project in GitLab:

  • Log in to your GitLab account.
  • Click on the "+" icon in the top left corner of the dashboard, and select "New project/repository".
  • Select the type of project you want to create. For our needs, "Create blank project" is a reasonable option.

Creating a new project

Let's create a repository for a new project. I will be using the Polls app from the official Django tutorial. If you have a different project in mind, please change the values accordingly.

For the project name, you can enter "Django Polls". For the project URL, select your username for the namespace. Assuming that you have JavaScript enabled, the project slug should be populated from the name with the value "django-polls", but if it is not, you can enter it manually. I recommend using the same value for the slug as the name of the repository's root directory.

Visibility defines whether the project is public or private. As I will be deploying the Polls app, public is fine. If you are working on commercial applications, you can set it to private.

Uncheck the Initialize repository with a README checkbox. While it contains useful information related to GitLab, it's also quite noisy. More importantly, it conflicts with the flow presented in this chapter, as it forces you to first clone the repository and add your project to the existing directory.

Finally, click on "Create project", and you should see an empty repository with some useful information.

After following these steps, you should now be ready to push a local repository to GitLab. We will start a fresh Django project, and push it in the next chapter.

GitHub

GitHub is another popular web-based platform for source code management. It offers many of the same features as GitLab, including version control, issue tracking, and continuous integration and deployment (CI/CD).

As I will be using GitLab-CI later in this book, I will not be covering GitHub at this time, but while the user interface will differ slightly, most of the flow will be the same, with GitHub Actions being a major exception. Feel free to use GitHub if you prefer.