GitLab – Squashing Commits ”; Previous Next Description Squashing is a way of combining all commits into one when you are obtaining a merge request. Steps for Squashing Commits Step 1 − Go to your project directory and check out a new branch with the name squash-chapter by using the git checkout command − The flag -b indicates new branch name. Step 2 − Now, create a new file with two commits, add that file to working directory and store the changes to the repository along with the commit messages as shown below − Step 3 − Now, squash the above two commits into one commit by using the below command − $ git rebase -i HEAD~2 Here, git rebase command is used to integrate changes from one branch to another and HEAD~2 specifies last two squashed commits and if you want to squash four commits, then you need to write as HEAD~4. One more important point is, you need atleast two commits to complete the squash operation. Step 4 − After entering the above command, it will open the below editor in which you have to change the pick word to squash word in the second line (you need to squash this commit). Now press the Esc key, then colon(:) and type wq to save and exit from the screen. Step 5 − Now push the branch to remote repository as shown below − Print Page Previous Next Advertisements ”;
Category: gitlab
GitLab – Milestones
GitLab – Milestones ”; Previous Next Description Milestones are used for arranging issues and merge requests into a determined group which can achieved within a specified amount of time by setting a start and due date. Steps for Creating Milestones Step 1 − Login to your GitLab account, go to your project and click on the Milestones option under Issues tab − Step 2 − Click on the New milestone button − Step 3 − Now enter the title, description, start and due date and click on Create milestone button as shown in the below image − Step 4 − After creating a milestone, it will display a message saying ”Assign some issues to this milestone” as shown below − Step 5 − Now go to Issues tab and click on the New issue button to create an issue for the milestone − Step 6 − Now, fill the information such as title, description and if you want, you can select a user to assign an issue, milestone, labels upon operation or could be choose by developers themselves later. Click on the Submit issue button. Step 7 − After creating a issue, you will get overview of an issue along with title and description. At right side, click on Edit option and assign milestone for the issue under Milestone section − Step 8 − Now go back to Milestones section and you will see the added milestone along with created issue − Print Page Previous Next Advertisements ”;
GitLab – Create Backup
GitLab – Create Backup ”; Previous Next GitLab allows to take backup copy of your repository by using simple command. In this chapter, we will discuss about how to take backup copy in the GitLab − Step 1 − First, login to your GitLab server using SSH (Secure Shell). Step 2 − Create the backup of GitLab by using the below command − sudo gitlab-rake gitlab:backup:create Step 3 − You can exclude some directories from the backup by adding environment variable SKIP as shown below − sudo gitlab-rake gitlab:backup:create SKIP = db,uploads Step 4 − The backup tar file will get created in the default /var/opt/gitlab/backups directory. Navigate to this path and type ls -l to see the created backup file − Print Page Previous Next Advertisements ”;
GitLab – Add a File
GitLab – Add a File ”; Previous Next In this chapter, we will discuss about how to add a file to a project in the GitLab. We can add file in two ways − Using Command Line Interface Using Web Interface Creating a file using Command Line Interface Step 1 − To create a file by using command line interface, type the below command in your project directory − Step 2 − Now go to your project directory and you will see the created file − Creating a file using Web Interface Step 1 − You can create a new file, by clicking on the ”+” button which is at the right side of the branch selector in the dashboard − Step 2 − Enter the file name, add some content in the editor section and click on the Commit changes button to create the file. Step 3 − Now you will get a successful message after creating the file as shown below − Print Page Previous Next Advertisements ”;
GitLab – Git Commands
GitLab – Git Commands ”; Previous Next Description Git commands are used for sharing and combining the code easily with other developers. Git Commands Following are the some basic Git commands can be used to work with Git − The version of the Git can be checked by using the below command − $ git –version Add Git username and email address to identify the author while committing the information. Set the username by using the command as − $ git config –global user.name “USERNAME” After entering user name, verify the entered user name with the below command − $ git config –global user.name Next, set the email address with the below command − $ git config –global user.email “[email protected]” You can verify the entered email address as − $ git config –global user.email Use the below command to check the entered information − $ git config –global –list You can pull the latest changes made to the master branch by using the below command − $ git checkout master You can fetch the latest changes to the working directory with the below command − $ git pull origin NAME-OF-BRANCH -u Here, NAME-OF-BRANCH could be ”master” or any other existing branch. Create a new branch with the below command − $ git checkout -b branch-name You can switch from one branch to other branch by using the command as − $ git checkout branch-name Check the changes made to your files with the below command − $ git status You will see the changes in red color and add the files to staging as − $ git add file-name Or you can add all the files to staging as − $ git add * Now send your changes to master branch with the below command − $ git push origin branch-name Delete the all changes, except unstaged things by using the below command − $ git checkout . You can delete the all changes along with untracked files by using the command as − $ git clean -f To merge the different branch with the master branch, use the below command − $git checkout branch-name $ git merge master You can also merge the master branch with the created branch, by using the below command − $git checkout master $ git merge branch-name Print Page Previous Next Advertisements ”;
GitLab – SSH Key Setup
GitLab – SSH Key Setup ”; Previous Next Description The SSH stands for Secure Shell or Secure Socket Shell used for managing the networks, operating systems and configurations and also authenticates to the GitLab server without using username and password each time. You can set the SSH keys to provide a reliable connection between the computer and GitLab. Before generating ssh keygen, you need to have Git installed in your system. Creating SSH Key Step 1 − To create SSH key, open the command prompt and enter the command as shown below − C:−ssh-keygen It will prompt for ”Enter file in which to save the key (//.ssh/id_rsa):”, just type file name and press enter. Next a prompt to enter password shows ”Enter passphrase (empty for no passphrase):”. Enter some password and press enter. You will see the generated SSH key as shown in the below image − Step 2 − Now login to your GitLab account and click on the Settings option. Step 3 − To create SSH key, click on the SSH keys tab at left side of the menu. Step 4 − Now go to C drive, you will see the file with .pub extension which was generated in the first step. Step 5 − Next open the key.pub file, copy the SSH key and paste it in the highlighted Key box as shown in the below image − Step 6 − Click on the Add Key button, to add SSH key to your GitLab. You will see the fingerprint (it is a short version of SSH key), title and created date as shown in the image below − Print Page Previous Next Advertisements ”;
GitLab – Installation
GitLab – Installation ”; Previous Next You can install the GitLab runner on different operating systems, by installing Git versioning system and creating user account in the GitLab site. Git is a version control system used for − Handling the source code history of projects Tracking changes made to files Handling small and large projects with speed and efficiency To collaborate with other developers on different projects GitLab is a Git-based platform provides remote access to Git repositories and helpful for software development cycle by creating private and public repositories for managing the code. GitLab supports different types of operating systems such as Windows, Ubuntu, Debian, CentOS, open SUSE and Raspberry Pi 2. In this chapter, we will discuss about how to install GitLab on Windows and Ubuntu operating systems − Installation of GitLab on Windows: Step 1 − First create a folder called ”GitLab-Runner” in your system. For instance, you can create in C drive as C:GitLab-Runner. Step 2 − Now download the binary for x86 or amd64 and copy it in the folder created by you. Rename the downloaded binary to gitlab-runner.exe. Step 3 − Open the command prompt and navigate to your created folder. Now type the below command and press enter. C:GitLab-Runner>gitlab-runner.exe register Step 4 − After running the above command, it will ask to enter the gitlab-ci coordinator URL. Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/): https://gitlab.com Step 5 − Enter the gitlab-ci token for the runner. Please enter the gitlab-ci token for this runner: xxxxx To get the token, login to your GitLab account − Now go to your project − Click on the CI/CD option under Settings tab and expand the Runners Settings option. Under Runners Settings section, you will get the token as shown in the image below − Step 6 − Enter the gitlab-ci description for the runner. Please enter the gitlab-ci description for this runner: [Admin-PC]: Hello GitLab Runner Step 7 − It will ask to enter the gitlab-ci tags for the runner. Please enter the gitlab-ci tags for this runner (comma separated): tag1, tag2 You can change these tags in the GitLab”s user interface later. Step 8 − You can lock the Runner to current project by setting it to true value. Whether to lock the Runner to current project [true/false]: [true]: true After completing above steps, you will get the successful message as ”Registering runner… succeeded”. Step 9 − Now enter the Runner executor for building the project. Please enter the executor: parallels, shell, docker+machine, kubernetes, docker- ssh+machine, docker, docker-ssh, ssh, virtualbox: docker We have used the selector as ”docker” which creates build environment and manages the dependencies easily for developing the project. Step 10 − Next it will ask for default image to be set for docker selector. Please enter the default Docker image (e.g. ruby:2.1): alpine:latest Step 11 − After completing the above steps, it will display the message as ”Runner registered successfully”. The below image will describe the working flow of above commands − Step 12 − Now go to your project, click on the CI/CD option under Settings section and you will see the activated Runners for the project. You can see the GitLab Runner configuration in the config.toml file under the GitLab-Runner folder as shown below − concurrent = 1 check_interval = 0 [[runners]] name = “Hello GitLab Runner” url = “https://gitlab.com” token = “40ceed29eec231fa9e306629cae4d7” executor = “docker” [runners.docker] tls_verify = false image = “alpine:latest” privileged = false disable_cache = false volumes = [“/cache”] shm_size = 0 [runners.cache] Installation of GitLab on Ubuntu The GitLab can be installed on Ubuntu system by using Omnibus package which provides different services to run GitLab. The Omnibus package provides necessary components of GitLab, establishes the configurations and project metadata which can be used in user”s system. The following steps describe installation of GitLab on Ubuntu − Step 1 − First, login to your GitLab server using SSH (Secure Shell). Step 2 − Next, download the Omnibus package − wget https://downloads-packages.s3.amazonaws.com/ubuntu-14.04/gitlab-ce_7.10.4~omnibus-1_amd64.deb Step 3 − Install the postfix − sudo apt-get install postfix Postfix is a open source mail transfer agent used to deliver the email notifications. Step 4 − While installing Postfix, it will ask type of installation; then select the Internet Site option. Next, it will show Postfix configuration along with the system mail name as shown in the image − Step 5 − Install the dpkg (package manager for debian system) for managing the installed packages − sudo dpkg -i gitlab-ce_7.10.4~omnibus-1_amd64.deb Step 6 − To have the changes take effect, you need to reconfigure the GitLab by using the below command − sudo gitlab-ctl reconfigure Step 7 − Check the status of the GitLab services by using below command − sudo gitlab-ctl status If you want to install GitLab from the source, then install some dependencies on the server and need to setup the database by using the PostgreSQL. It is described in the Environment setup chapter. You can install the coordinator to build a web interface and control build instances. For more information, you can check the Installation of Coordinator chapter. Print Page Previous Next Advertisements ”;
GitLab – Create Project
GitLab – Create Project ”; Previous Next In this chapter, we will discuss about how to create a new project in the GitLab. Step 1 − To create new project, login to your GitLab account and click on the New project button in the dashboard − Step 2 − It will open the New project screen as shown below in the image − Enter the project name, description for the project, visibility level (accessing the project”s visibility in publicly or internally) and click on the Create project button. Step 3 − Next it will create a new project (here given the project name as first-gitlab-prjt) with successful message as shown below − Push the Repository to Project Step 4 − You can clone the repository to your local system by using the git-clone command − The clone command makes a copy of repository into a new directory called first-gitlab-prjt. Step 5 − Now go to your newly created directory and type the below command − C:>cd first-gitlab-prjt C:first-gitlab-prjt>touch README.md The above command creates a README.md file in which you can put the information about your folder. Step 6 − Add the README.md file to your created directory by using the below command − C:first-gitlab-prjt>git add README.md Step 7 − Now store the changes to the repository along with the log message as shown below − C:first-gitlab-prjt>git commit -m “add README” The flag -m is used for adding a message on the commit. Step 8 − Push the commits to remote repository which are made on the local branch − C:first-gitlab-prjt>git push -u origin master The below image depicts the usage of above commands in pushing the commits to remote repository − Print Page Previous Next Advertisements ”;
GitLab – Create Groups
GitLab – Create Groups ”; Previous Next Description Creating group helps to connect multiple repositories and allows members to access the project by giving permissions on the group level. Steps for Creating Group Step 1 − Login to your GitLab account and click on the Groups menu − Step 2 − Next, you will get the below screen and click on the New group button to create a group − Step 3 − Enter the Group name, Description, visibility level(Private/Public/Internal) and also you can set the image for the group of your choice which should be within 200kb in size. Now click on the Create group button. Step 4 − Next, it will display the success message after creating the group as shown below − Step 5 − Now, go back to your Groups section and you will see the created group in the list − Print Page Previous Next Advertisements ”;