Here are the detailed steps, starting from cloning
a GitLab repository to creating a branch, pushing
changes, and raising a Merge Request (MR), ultimately
merging the changes into the master
branch.
Prerequisites
- Git is
installed on your machine.
- You have access to the GitLab repository.
- GitLab credentials (username/password or SSH keys) are ready.
1. Clone the GitLab Repository
Step 1: Get the Clone URL
- Log in
to your GitLab account.
- Navigate
to the repository you want to clone.
- Click
the Clone button on the repository
page.
- Copy the
HTTPS or SSH URL.
Step 2: Clone the Repository
- Open
your terminal (Linux/macOS) or Git Bash (Windows).
- Run the
following command:
git clone <repository-URL>
Example:
git clone https://gitlab.com/username/project.git
Step 3: Navigate to the Project Directory
- Change
to the cloned project directory:
cd project-name
2. Create a New Branch (Best Practice for Collaboration)
Step 4: Create and Switch to a New Branch
Create
a new branch to work on your changes. This avoids making changes directly to master
:git checkout -b <branch-name>
Example:
git checkout -b feature-new-functionality
3. Make Changes to the Codebase
Step 5: Modify or Add Files
- You can
now start modifying or adding files.
- To check
the status of your changes:
git status
4. Stage, Commit, and Push Your Changes
Step 6: Stage the Changes
- Add the
files you want to include in the commit:
git add <file-name>
To add all modified files:
git add .
Step 7: Commit Your Changes
- Once files are staged, commit them with a meaningful message
git commit -m "Descriptive commit message"
Step 8: Push Your Branch to GitLab
- Push
your branch to the remote repository:
git push origin <branch-name>
Example:
git push origin feature-new-functionality
5. Raise a Merge Request (MR)
Step 9: Open GitLab and Navigate to Your Repository
- Log in
to GitLab and navigate to your repository.
- GitLab
may prompt you to create a Merge Request for the newly pushed branch. If
so, click Create
Merge Request.
Step 10: Manually Create a Merge Request (if not prompted)
- Click on
Merge Requests in the left
sidebar of the repository.
- Click New Merge Request.
Step 11: Select the Source and Target Branches
- Source branch: The branch
you created (e.g.,
feature-new-functionality
). - Target branch: The branch
you want to merge into (typically
master
).
Step 12: Fill in the Merge Request Details
- Title: Add a descriptive
title.
- Description: Provide a
summary of the changes.
- Assign reviewers
(optional) if working in a team.
Step 13: Submit the Merge Request
- Click Submit Merge Request to
open the MR for review.
6. Review and Merge the Changes
Step 14: Review and Feedback (Optional)
- Team members can review the MR, request changes, or approve it.
- If changes are requested, make the required modifications locally, commit, and push again
git push origin <branch-name>
Step 15: Merge the Request
- Once the
MR is approved, you or the reviewer can merge the branch.
- Navigate
to the Merge Request page in GitLab and click Merge.
7. Clean Up and Update Local Master
Step 16: Delete the Branch (Optional)
- Once
merged, you can delete the feature branch in GitLab or locally:
git branch -d <branch-name>
Example:
git branch -d feature-new-functionality
Step 17: Pull the Latest Changes to Your Local Master
- Switch
to the
master
branch:
git checkout master
Pull the latest changes:
git pull origin master
Following these steps will guide you from cloning the repository, creating a
feature branch, pushing changes, and raising a Merge Request to merge your
changes into the master
branch.
Post a Comment