Day 3: Understanding Git Basics and GitLab's Repository Structure

Day 3: Understanding Git Basics and GitLab's Repository Structure

Welcome to Day 3 of our GitLab CI/CD journey! Having set up your GitLab account and created a project, it's time to understand the basics of Git and GitLab's repository structure. Let's dive right in!

Git Basics

Git is a distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Here are a few essential Git concepts you should know:

  • Repository: A repository (or "repo") is like a folder for your project that contains all of your project's files and stores each file's revision history. GitLab also allows you to interact with others on your team and to manage your repository.

  • Commit: A commit, or "revision", is an individual change to a file (or set of files). It's like a snapshot of your project at a particular point in time that you can refer back to later if needed.

  • Branch: A branch is a parallel version of a repository. It is contained within the repository but does not affect the primary or 'master' branch allowing you to work freely without disrupting the live version. When you've made the changes you want to, you can merge your branch back into the master branch to publish your changes.

Working with GitLab's Repository

Every GitLab project comes with a built-in Git repository. Here's a step-by-step guide on how you can make changes to your project using Git:

  1. Clone the repository: The first step is to clone the repository to your local machine. This can be done with the git clone command followed by the URL of your GitLab repository. This creates a local copy of the entire project.

  2. Create a new branch: It's good practice to create a new branch when you're working on a new feature or bug fix. You can create a new branch with the git branch command followed by the name of your new branch.

  3. Make changes and commit: Once you're happy with your changes, you can commit them. First, you need to stage your changes with the git add command. After staging, you can commit your changes with the git commit command followed by a message describing what you've changed.

  4. Push changes: After committing your changes, you'll need to push them to the GitLab repository with the git push command. If you're working on a new branch, you'll also need to specify the name of that branch.

  5. Merge changes: Once your changes are pushed to GitLab, you can merge them into the master branch. You can do this in GitLab's interface by creating a new merge request.

Understanding Git and GitLab's repository structure is the foundation for working efficiently with code in a collaborative environment. With the knowledge you've gained today, you're ready to start contributing to your project.

In tomorrow's blog, we'll take you through the process of setting up your first CI/CD pipeline on GitLab.

Remember, if you encounter any issues, GitLab's documentation is a great resource. See you tomorrow!