GitLab Day 1
Steps
Here’s an overview of what I am going to do:
1. Create a sample project.2. Clone the repository.3. Create a branch and make your changes.4. Commit and push your changes.5. Merge your changes.6. View your changes in GitLab.
Create a sample project
To start, create a sample project in GitLab.
1. In GitLab, on the left sidebar, at the top, select Create new () and New project/repository.
2. For Project name, enter Chetan. The project slug is generated for you. This slug is the URL you can use to access the project after it’s created.
3. Ensure Initialize repository with a README is selected. How you complete the other fields is up to you.
Select Create project Clone the repository
Now you can clone the repository in your project. Cloning a repository means you’re creating a copy on your computer, or wherever you want to store and work with the files.
1. On your project’s overview page, in the upper-right corner, select Code, then copy the URL for Clone with SSH.
Create a branch and make changes
Now that you have a copy of the repository, create your own branch so you can work on your changes independently.
Create a new branch called test01-Branch.
git checkout -b test01-Branch
In a text editor like Visual Studio Code, Sublime, vi, or any other editor, open the README.md file and add this text:
Hello world! I'm using Git!
Save the file.
Git keeps track of changed files. To confirm which files have changed, get the status.
git status
You should get output similar to the following:
On branch test01-Branch
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
Now that you have a copy of the repository, create your own branch so you can work on your changes independently.
Create a new branch called
test01-Branch.
vi, or any other editor, open the README.md file and add this text:Save the file.
Git keeps track of changed files. To confirm which files have changed, get the status.
You should get output similar to the following:
On branch test01-Branch Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: README.md no changes added to commit (use "git add" and/or "git commit -a")
Commit and push your changes
You’ve made changes to a file in your repository. Now it’s time to record those changes by making your first commit.
Add the README.md file to the staging area. The staging area is where you put files before you commit them.
git add README.md
Confirm the file is staged:
git status
You should get output similar to the following, and the filename should be in green text.
On branch test01-Branch
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: README.md
Now commit the staged file, and include a message that describes the change you made. Make sure you surround the message in double quotes (“).
git commit -m "I added text to the README file"
The change has been committed to your branch, but your branch and its commits are still only available on your computer. No one else has access to them yet. Push your branch to GitLab:
git push origin test01-Branch test
Your branch is now available on GitLab and visible to other users in your project.
You’ve made changes to a file in your repository. Now it’s time to record those changes by making your first commit.
Add the
README.mdfile to the staging area. The staging area is where you put files before you commit them.
Merge your changes
Now you’re ready to merge the changes from your test01-Branch branch to the default branch (main).
Check out the default branch for your repository.
git checkout main
Merge your branch into the default branch.
git merge example-tutorial-branch
Push the changes.
git push
In this tutorial, I Have merged My branch directly to the default branch for My repository. In GitLab, we typically use a merge request to merge our branch.
Now you’re ready to merge the changes from your test01-Branch branch to the default branch (main).
Check out the default branch for your repository.
Push the changes.
View your changes in GitLab
You did it! You updated the README.md file in your branch, and you merged those changes into the main branch.
Let’s look in the UI and confirm your changes. Go to your project.
- Scroll down and view the contents of the
README.md file. Your changes should be visible. Above the README.md file, view the text in the Last commit column. Your commit message is displayed in this column:
You did it! You updated the README.md file in your branch, and you merged those changes into the main branch.
Let’s look in the UI and confirm your changes. Go to your project.
- Scroll down and view the contents of the
README.mdfile. Your changes should be visible. Above the
README.mdfile, view the text in the Last commit column. Your commit message is displayed in this column:


0 Comments