DEV Community

Ophélie
Ophélie

Posted on

A Comprehensive Guide to GitHub and GitLab: Features and Step-by-Step Guide

In this article, we’ll explore the key options available in both GitHub and GitLab, and walk you through how to use them, step-by-step.

Part 1: GitHub

GitHub is one of the most widely used platforms for version control and collaboration, built around Git. It’s ideal for both individuals and teams working on software development projects.

Key Features of GitHub

  1. Repositories (Repos)
    • Where all the files for a project are stored.
  2. Branches
    • Different versions of your repository, enabling parallel development.
  3. Pull Requests
    • Allows you to propose changes to the codebase and collaborate with others.
  4. Issues
    • Track bugs, enhancements, and more.
  5. Actions (CI/CD)
    • Automate your software development workflows.
  6. Wiki
    • Documentation area for your projects.
  7. Projects
    • Organize tasks and development milestones.

Step-by-Step Guide to Using GitHub

1. Create a GitHub Account

  • Go to GitHub and sign up for a free account.
  • Verify your email and complete your profile setup.

2. Create a New Repository

  1. Once logged in, click on the + icon at the top-right of the screen.
  2. Choose New Repository.
  3. Name your repository (e.g., my-project).
  4. Choose to make it public or private.
  5. Select if you want to add a README file, .gitignore, or license.
  6. Click Create Repository.

3. Cloning a Repository Locally

  • Open a terminal (or Git Bash) and run the following command:

     git clone https://github.com/your-username/my-project.git
    
  • This will download the repository to your local machine.

4. Creating a Branch

  • Use branches to work on features without affecting the main codebase.
  • In your terminal:

     git checkout -b feature-branch
    
  • This creates and switches to a new branch.

5. Making Changes and Committing

  • After making changes to your code, run:

     git add .
     git commit -m "Describe your changes"
    

6. Pushing Changes

  • Push your changes to GitHub:

     git push origin feature-branch
    

7. Creating a Pull Request

  1. Go to your repository on GitHub.
  2. Click on the Pull Requests tab.
  3. Select New Pull Request.
  4. Choose your branch and compare it to the main branch.
  5. Add a description of your changes.
  6. Click Create Pull Request.

8. Merging Pull Requests

  • Once reviewed and approved, click Merge to integrate the changes into the main branch.

9. Using GitHub Actions

  1. In your repository, go to the Actions tab.
  2. Choose a workflow template, such as Node.js, Python, etc.
  3. Customize the workflow as needed and click Start commit.

10. Managing Issues

  1. Go to the Issues tab in your repository.
  2. Click New Issue to track bugs or feature requests.
  3. Assign team members and add labels to manage issues effectively.

Part 2: GitLab

GitLab is a comprehensive DevOps platform that provides a wide array of features for CI/CD, project management, and version control. It's highly preferred by teams needing an all-in-one solution.

Key Features of GitLab

  1. Repositories
    • Similar to GitHub, it’s the core of any project.
  2. Branches
    • Used for development and parallel work streams.
  3. Merge Requests
    • GitLab’s version of pull requests for code reviews.
  4. Pipelines (CI/CD)
    • Automate your builds, tests, and deployments.
  5. Issues and Milestones
    • For tracking work progress and bugs.
  6. Wiki and Snippets
    • Share and manage documentation.
  7. Security and Compliance
    • Features for code scanning, vulnerability management, and permissions.

Step-by-Step Guide to Using GitLab

1. Create a GitLab Account

  • Head to GitLab and register for a free account.
  • Confirm your email and set up your profile.

2. Create a New Project

  1. Once logged in, click New Project.
  2. Choose to create a blank project or import an existing one.
  3. Name your project (e.g., gitlab-project).
  4. Decide if the project will be private, internal, or public.
  5. Click Create Project.

3. Cloning a Repository Locally

  • Similar to GitHub, use:

     git clone https://gitlab.com/your-username/gitlab-project.git
    

4. Creating a Branch

  • To create a new branch:

     git checkout -b feature-branch
    

5. Making Changes and Committing

  • Make the necessary changes to your project.
  • Use the same Git commands as GitHub:

     git add .
     git commit -m "Update project"
    

6. Pushing Changes

  • Push your changes to GitLab:

     git push origin feature-branch
    

7. Creating a Merge Request

  1. In GitLab, navigate to your project.
  2. Click the Merge Requests tab.
  3. Select New Merge Request.
  4. Compare your feature branch with the target branch (usually main).
  5. Provide a description of the changes and click Submit Merge Request.

8. Merging Merge Requests

  • After the merge request is approved, click Merge to integrate the branch.

9. Setting Up GitLab CI/CD

  1. Navigate to the CI / CD section in your project.
  2. Add a .gitlab-ci.yml file to your repository for specifying the CI/CD pipeline.
  3. GitLab will automatically run jobs based on this configuration.

10. Managing Issues and Milestones

  • Go to the Issues tab.
  • Click New Issue to track bugs, tasks, or features.
  • Create Milestones to group issues and track progress over a sprint or project phase.

Conclusion

Both GitHub and GitLab offer powerful tools for code collaboration and version control. GitHub is a simple and widely used platform with strong community integration, while GitLab is more comprehensive with built-in CI/CD pipelines and DevOps features.

Choosing Between GitHub and GitLab

  • GitHub is ideal if you want ease of use, wide adoption, and access to open-source communities.
  • GitLab excels if you need a complete DevOps solution with robust automation, security, and compliance tools.

No matter your choice, these platforms will significantly improve your software development workflows.

Top comments (0)