Getting Started with GitLab
GitLab is a DevOps platform that provides version control, CI/CD pipelines, and collaborative tools for software development. Here's an overview of important terminologies and a practical example to help you get started.
Important GitLab Terminologies
- Repository (Repo): A project folder where your codebase is stored.
Example: A repository named my-app contains your application's source code.
- Branch: A parallel version of your project.
Default branch: main or master.
Example: feature-login branch for working on the login feature.
- Merge Request (MR): A request to merge changes from one branch to another.
Example: Merge the feature-login branch into main.
- Pipeline: A set of automated steps for building, testing, and deploying code.
Example: CI/CD pipelines.
- Runner: A GitLab agent that executes CI/CD jobs.
Example: Shared runners hosted by GitLab.
- Jobs: Tasks defined in a pipeline.
Example: Running unit tests or deploying an application.
- Artifacts: Files generated by jobs that can be downloaded or passed to subsequent jobs.
Example: Test reports.
- Tags: Mark specific points in history.
Example: v1.0.0 tag for the first release version.
- Groups: Organize projects and manage permissions.
Example: A team-backend group containing all backend repositories.
- Issues: Track bugs, enhancements, or tasks in your project.
Example: Create an issue to fix a bug.
Setting Up GitLab
- Create an Account:
Sign up at GitLab.
- Create a New Project:
Go to Projects → New Project → Choose a blank project.
Give it a name, e.g., my-app.
- Clone the Repository:
git clone https://gitlab.com//my-app.git
- Add Files and Push:
cd my-app
echo "# My App" > README.md
git add README.md
git commit -m "Initial commit"
git push origin main
Example GitLab Workflow
Step 1: Create a Feature Branch
git checkout -b feature-login
Make changes to your code and commit:
git add .
git commit -m "Added login feature"
git push origin feature-login
Step 2: Open a Merge Request
Navigate to your project in GitLab.
Go to Merge Requests → New Merge Request.
Select feature-login as the source branch and main as the target branch.
Submit the merge request.
CI/CD Pipeline Example
- Create a .gitlab-ci.yml File: This file defines the CI/CD pipeline.
stages:
- build
- test
- deploy
build-job:
stage: build
script:
- echo "Building the application..."
test-job:
stage: test
script:
- echo "Running tests..."
deploy-job:
stage: deploy
script:
- echo "Deploying the application..."
- Push the File to GitLab:
git add .gitlab-ci.yml
git commit -m "Added CI/CD pipeline"
git push origin main
- View Pipeline:
Go to CI/CD → Pipelines to monitor pipeline execution.
Summary
GitLab simplifies collaboration and automation in development workflows. By understanding key terminologies and practicing with simple examples like branch creation, merge requests, and CI/CD pipelines, you can effectively utilize GitLab in your projects.
Top comments (0)