Git Tutorial – Part 2: Understanding Git and Connecting to Your Self-Hosted GitLab
Understanding Git and Connecting to Your Self-Hosted GitLab : In this tutorial, you will learn how to:
- Understand the difference between Git and GitLab.
- Create your first project in your self-hosted GitLab server.
- Clone a repository to your Windows 11 computer.
- Verify the connection between your local machine and GitLab.
What is Git?
Git is a distributed Version Control System (VCS) used to:
- Track changes made to files.
- Maintain a complete history of code changes.
- Allow multiple developers to work on the same project simultaneously.
- Restore previous versions if needed.
Git works locally on your computer.
What is GitLab?
GitLab is a web-based platform that hosts Git repositories.
It allows you to:
- Store repositories on a central server.
- Collaborate with team members.
- Manage projects.
- Review code using Merge Requests.
- Track issues and bugs.
- Control user permissions.
In your environment, GitLab is hosted on your organization’s own server (self-hosted GitLab).
Git vs GitLab
| Git | GitLab |
|---|---|
| Installed on your computer | Hosted on a server |
| Tracks file changes | Stores Git repositories |
| Works offline | Requires network access |
| Command-line tool | Web application |
Step 1: Sign In to Your Self-Hosted GitLab
- Open your web browser.
- Navigate to your organization’s GitLab URL.
Example:
https://gitlab.yourcompany.com
- Enter your username and password.
- Click Sign In.
Step 2: Create Your First Project
After signing in:
- Click New Project.
- Select Create Blank Project.
- Enter the following information.
Project Name
GitTutorial
Project Slug
gittutorial
Visibility
Choose one of the following based on your organization’s policy:
- Private
- Internal
- Public
Most organizations use Private.
- Check the option:
Initialize repository with a README
- Click Create Project.
Your first repository is now created.
Step 3: Copy the Repository URL
Once the project is created:
Locate the Clone button.
You will see two options:
HTTPS
Example
https://gitlab.yourcompany.com/training/gittutorial.git
SSH
Example
git@gitlab.yourcompany.com:training/gittutorial.git
For beginners, use HTTPS unless your organization specifically requires SSH.
Copy the HTTPS URL.
Step 4: Open Visual Studio Code
- Open Visual Studio Code.
- Open the integrated terminal by selecting:
Terminal
→ New Terminal
or press
Ctrl + `
Step 5: Navigate to Your Working Folder
Example:
cd C:\Projects
If the folder does not exist:
mkdir C:\Projects
cd C:\Projects
Step 6: Clone the Repository
Run:
git clone https://gitlab.yourcompany.com/training/gittutorial.git
Example output:
Cloning into 'gittutorial'...
Receiving objects: 100%
Resolving deltas: 100%
Git downloads the repository from GitLab to your computer.
Step 7: Open the Project
Move into the project folder:
cd gittutorial
Open it in Visual Studio Code:
code .
The project is now ready for development.
Step 8: Verify the Remote Repository
Run:
git remote -v
Example output:
origin https://gitlab.yourcompany.com/training/gittutorial.git (fetch)
origin https://gitlab.yourcompany.com/training/gittutorial.git (push)
This confirms that your local repository is connected to the remote GitLab repository.
Step 9: Check Repository Status
Run:
git status
Example output:
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
This indicates:
- You are on the main branch.
- Your local repository is synchronized with GitLab.
- There are no pending changes.
Summary
This is all about Understanding Git and Connecting to Your Self-Hosted GitLab. You have successfully learned how to:
- Understand the roles of Git and GitLab.
- Create a project in your self-hosted GitLab instance.
- Clone a repository to your Windows 11 PC.
- Open the project in Visual Studio Code.
- Verify the remote connection.
- Check the repository status.
Next Tutorial
The next chapter will cover:
- Creating new files
- Understanding the Git lifecycle
- Using
git status - Staging changes with
git add - Creating commits with
git commit - Viewing commit history with
git log - Understanding the difference between the Working Directory, Staging Area, Local Repository, and Remote Repository
Click Here to view the Next tutorial.
Tutorial Index:
- Part 1: Git Installation and Setup Guide
- Part 2: Understanding Git and Connecting to Your Self-Hosted GitLab
- Part 3: Git Workflow – Creating, Staging, and Committing Changes
- Part 4: Working with Remote Repositories (Push, Pull, and Fetch)
- Part 5: Working with Git Branches
- Part 6: Understanding and Resolving Merge Conflicts
