Git is a version control system used to locally check changes in a project or folder. Once we add Git to our project it will start tracking for changes and also push and pull changes from remote repositories like GitHub, BitBucket and GitLab.
GitLab provides a service that allows you to host a project or folder on a remote repository and has some additional features to help in software delivery life cycle and CI & CD. GitHub and BitBucket provide similar kinds of service as GitLab.
Some features include:
Managing code
Code sharing
Wiki or code documentation
Bug tracking
CI & CD
Creating an account on GitLab:
Link: https://gitlab.com/users/sign_up or alternatively you can login with your existing GitHub, Google account or other accounts available.
Fill in project name.
Change the visibility - private/public.
Give description (optional).
Click on create project.
After creating the project copy your project link or get it from a clone url.
Project link: https://gitlab.com/shubham-dota/my-first-project.git
git init
– make an existing directory as a Git repository.git clone [url]
- retrieve an entire repository from a hosted location via URL.git status
- show changes in files in working directory, staged for your next commit.git add [file]
- add a file in the working directory to the staging area.git commit -m “[commit message]”
- commits staged content.git pull
- fetch and merge any commits from the tracking remote branch.git push [ ] [branch]
– pushes the code from local to remote repository.
There are many more commands in Git.
Refer : https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet
Download Git for your OS.
Install Git as per your OS. Click for Step by step process.
After installing type < git --version >
in CMD/terminal check if it’s installed.
Config your Git
1 2 3 4 5
git--global user.name“ < GitLab UserName > ”(To add Git user) git--global user.name(To check added user name) git config--global user.email "<GitLab Email>"(To add GitLab mail) git config--global user.email(To check added email) git config--global– list(To check the values set)
Create a new folder or project and add to Git.
1 2 3 4 5 6 7 8 9 10
Open terminal / CMD. Change directory to the project location and follow the commands. git init(To initialize Git) git status(To display state of current project) Now, create a file in the project directory and check for git status. git add < file name > or git add.(To add particular or all files) git status git commit– m“ commit message” git push - u“ < url of repo > ”<branch name> (To push files to GitLab)
Issues can be created for bugs, new features or anything related to the code in the repository. Issues are a kind of bug tracker in GitLab and are great to keep track of tasks, enhancements, and bugs for projects.
Labels are a way to categorize issues or tag issues for managing work on GitLab. Labels help to organize and tag work so that it can be tracked and we can work on the item we are interested in.
Login to GitLab account.
Go to the repository/project you want to create an issue for.
Go to the issues tab then click on the new issue button to create a new issue.
Fill in the information such as title and description.
You can use markdown to fill description.
You can assign the label.
Click on the submit issue button and you will get an overview of an issue along with title and description.
The title and description describes the issue.
Labels help to categorize and filter issues.
Milestones are a way to track issues by keeping time periods or by using phases like Beta launch or Release Candidate.
Labels are the best way to organize different types of issues. Issues can have many labels and issues can be filtered by labels.
Assignees - An issue can have an assignee that’s responsible for moving the issue forward.
In GitLab groups are the way to categorize and restrict the permission of multiple repositories.
Login to GitLab account and click on the groups menu.
Click on the new group button to create a group.
Enter the group name, visibility level (private/public). Now click on the create group button
Group has been created successfully.
A fork is a duplicate copy of a project. Forking a project or repository allows you to make changes without affecting the original project or repo. So whenever you want to make some changes without changing the original copy, we can create a fork and make changes. Later on it can be merged with the original project.
Login to GitLab account.
Go to your project.
Click on the fork button and select the namespace.
If you are getting a namespace error you’ll need to create a group.
Once you are done with the changes on the forked copy, you can merge it with the original branch.
Click on merge request.
Select source branch and branch name and then the target branch.
Click on compare branch and continue.
Submit merge.
This helps to connect to the GitLab server without using your username and password every time.
Open terminal and give command ssh-keygen
.
Enter the location to save the key.
Press enter and you’ll get your key.
Use any ssh-client like putty or git bash
Give command ssh-keygen
.
Enter the location to save the key.
Press enter and you’ll get your key.
Login to GitLab Account -> Settings -> SSH keys.
Add the key generated in id_rsa.pub
file.
Verify SSH key.
It is an open source continuous integration service which is included in GitLab, used to run jobs and send back results to GitLab.
For Mac
Go to terminal.
Give command brew install gitlab-runner
to install.
To start runner run brew services start gitlab-runner
.
Open terminal
Give gitlab-runner register
Enter GitLab instance URL.
Enter the token obtained to register the runner.
Enter description for the runner.
Input the tags associated with the runner, separated by commas.
Provide the runner executor.
Go to project settings and the CI/CD, then runner and check for activated runner.
Note
To get gitlab-ci token, go to project settings and then under settings go to CI/CD. In the runner section you’ll find the token.
For installing runner on Windows follow : https://docs.gitlab.com/runner/register/
In earlier days we used to build a project and then deploy the entire project on the server. But now most developers follow the agile concept. With agile we use CI - continuous integration. Consider there are four members in a team, one developer is working on a module and the same module is used by another developer. As a team we develop the project and after completion we combine the entire project and deploy the project. If anything goes wrong it will be very difficult to find what it is, where the bug is and who made the mistake. With CI, you can build the project and push it to the server, therefore it will be continuous integration. If you are using an IDE you can just right click and push the data to the server and the server will be responsible for continuous deployment. So we have:
CI (Continuous Integration): pushing the code to the server.
CD (Continuous Deployment): delivery/deployment of code.
Add .gitlab-ci.yml in the root folder on project/repository.
This file is used to configure pipeline and defines structure and order of the pipeline.
File gist : https://gist.github.com/shubham-dota/64760c6be1f1409bd9fafcece13bde30
Commit and push to repository.
Create GitLab runner for the project making sure the tags are the same as that provided in the yaml file.
Start the runner.
Now make any change to the project and then commit and push.
The gitlab-ci.yml will check for any commits and push in the project. You can check CI/CD jobs under your project getting triggered.