Installing and Using GitLab
To initiate a new repository, choose 'Create a new repository' to start with an empty one, then proceed to develop and commit code.
Alternatively, use 'Push an existing folder' when you already have source code ready to upload.
Cloning and Committing Files
After cloning the repository, create files within it and commit them to the repository.
Creating a Branch
Mainline vs Feature Development
In mainline development, all changes are made directly on the main branch (typically main or master).
In feature branching, new features are developed in separate branches derived from the main branch. Once completed, these branches undergo pipeline validation before merging into the main branch for release.
Feature branching workflow includes:
- Create a release branch from
main(e.g.,release-1.1.1). - Create feature branches from
main(e.g.,feature-1,feature-2). - After feature completion, merge the feature branch into the release branch.
- Deploy from the release branch acros environments (dev, staging, production).
- Finally, tag the
mainbranch up on successful deployment.
Fetching Feature Branches
Why fetch branches? To isolate feature development from the main branch, preventing accidental pollution of production-ready code.
Navigate to the project homepage and create a feature branch named feature-1-DEV based on main.
Developing and Committing Feature Branch Changes
Merging Feature Branches
Merge the feature branch feature-1-DEV into main via a Merge Request.
On the merge request page:
- Set a descriptive title.
- Add a detailed description of changes.
- Assign a reviewer for approval.
- Assign peers for code review.
- Optional delete the source branch post-merge (recommended for cleanup).
Once reviewed and approved by an administrator, the merge can proceed.
This completes a standard GitLab development cycle.
Transferring Projects to Subgroups
In GitLab, projects can be transferred to subgroups under Settings > General > Transfer Project. This action requires admin rights for the target group.
Permissions Overview:
- Guest: Can comment and view issues, cannot read/write repositories.
- Reporter: Clone code, cannot commit.
- Developer: Clone, develop, commit, and push code.
- Maintainer: Manage project settings, protect branches, manage members.
- Owner: Full control including visibility, deletion, and migration of projects.
Only Owners can transfer projects between groups.
Managing Git Submodules
A Git submodule allows embedding another Git repository as a subdirectory within a parent repository.
Submodule entries are stored in .gitmodules:
[submodule "module_name"]
path = file_path
url = repo_url
Adding a Submodule
- Initialize a new project.
- Clone it locally:
git clone https://github.com/xugaoxiang/gitDemo.git - Add a submodule:
git submodule add https://github.com/ultralytics/yolov5.git
The directory now includes a .gitmodules file listing submodule configurations.
Viewing Submodules
Check added submodules using:
git submodule
Committing Submodules
Add and commit the submodule:
git add .gitmodules
git commit -m "add drpo gitmodules"
git push origin main
Cloning Repositories with Submodules
When cloning, initialize and update submodules:
# Method 1
git submodule init
git submodule update
# Method 2 (preferred)
git clone https://github.com/xugaoxiang/gitDemo.git --recursive
Updating Submodules
To synchronize with remote updates:
git submodule update --remote
Removing Submodules
To remove a submodule:
-
Remove the submodule entry:
git rm yolov5 -
Edit
.gitmodulesto remove related lines. -
Update
.git/configaccordingly. -
Delete submodule directory from
.git/modules/.