Development: Connect git to GitLab for Small Projects
The git distributed version control system works with a variety of online services to provide storage and multiperson access to content. We recently covered the basics on how to set up and use the popular GitHub service. GitLab is another commonly used service. GitLab is the subject of today’s article.
Using GitLab to house your content, from the command line, is fairly straightforward.
New User Set up on GitLab
Go to the GitLab main signup page as a new user.
- Click “Register now”, right below the blue sign-in button.
- On the GitLab main sign-up page, enter the following:
1. First Name
2. Last Name
3. Username you’d like to use
4. Your email address
5. Your desired password
- Check the “I am not a robot” box and solve the visual puzzle.
- Click the blue “Register” button.
- Next, check your email for a confirmation message.
Click the “Confirm your account” link in the email.
- Return to your web login and enter your password.
- Press the blue “Sign In” button.
The “Welcome to GitLab, [your name]” page will appear for you to enter your role, title, who will be using this GitLab account and so on. When finished, press the blue “Continue” button.
At this point, the basic GitLab account is set up and ready for use.
Establish a New GitLab Repo
After the new GitLab user account details are settled, it’s time to set up a repository. For me, the task felt ambiguously defined because GitLab calls repositories “projects,” which may throw some readers off. But adding a new repository paves the way for pushing your software source code and other content up to the GitLab servers.
When you first log into GitLab using your username and password, you will land on your “Projects” page. Your current repositories will show up as a list. Click on the highlighted title to go directly to a repository. To start a new repository or as GitLab calls it, a project, press the blue “New Project” button, at the top right of the screen.
On the GitLab create new project page select the “Create blank project” link. Enter the following information on the create blank project page.
- Enter a project (repository) name and an optional description, in the appropriate text boxes. I used “hedley-the-skull” and “Space for Hedley-the-skull content”.
- Select your visibility level, either private or public.
- I also suggest un-checking the “Initialize repository with a README” box, so as not to cause problems with your initial content push from the Linux notebook command line. git will sometimes grumble that the online repository has already been initialized and new users won’t know how to fix it. Just make sure the new online repo is empty to avoid trouble.
- Press the blue “create repository” button.
Your new project (repository) page will appear. Arrow down and you’ll find convenient instructions on how to get content from your Linux notebook up to your GitLab repo, using the command line. You can also use web-based tools under the “Repository for this project is empty” heading.
Make note that your repository will appear at https://gitlab.com/[your user-name]/[project-name]. For example, my new repository would be https://gitlab.com/drtorq/hedley-the-skull.
Push a Repo up to GitLab
Sending your content up to GitLab, from the command line is similar to any other git service.
On the local Linux notebook machine:
Make and move into the new repo directory with a name of your choice.
drtorq%: mkdir [name of your new repo directory]
drtorq%: cd [name of your repo directory]
Use the a text editor or vi to create a few new text files, file1.txt, file2.txt, file3.txt
drtorq%: git init
Set up remote link to your GitLab repo:
drtorq%: git remote add origin [your gitlab repository]
Do your file adds.
drtorq%: git add .
Do your commit.
drtorq%: git commit -m “Initial commit”
If I tried to do a regular git push here, I’d get an error. I found that using the following line solved the problem:
drtorq%: git push --set-upstream origin master
→ username: [my GitLab user name]
→ p/w: [my GitLab password]
Finally, use the regular git push to sync the content on the GitLab servers.
drtorq%: git push -u origin main
Edit the text files, up on the browser, the same as in GitHub.
Pulling down changes to a repository is just as easy, from the Linux notebook.
drtorq%: git pull origin
Make a few edits to files up on your GitLab repository and see how they reflect in your local Linux notebook git repository files after a pull request.
Notice too that once you have files up in the GitLab repository, the menu interface changes. Without files, you’ll be asked to invite others to your repo and upload or create some new files. After files are created or synced with the git repo on your Linux notebook, you’ll simply see the files in your GitLab repo, from then on.
GitLab or GitHub?
Operation of GitLab and GitHub are pretty similar, when you interact with them via the Linux command line. First, you set up the git environments on the Linux notebook and the service. You then establish the links for the command line connection. Next, you edit, add, commit and push content up to the server. Updates roll down from the server with a pull.
For my small projects, this is adequate functionality and I could use either one. Of course, as your git utilization expands, it is always prudent to look ahead and explore how your platforms might boost productivity as you grow.
GitLab bills itself as an integrated DevOps system providing a comprehensive platform for managing code, deployment and system monitoring. A big feature of GitLab is that it has been more focused on continuous integration and continuous deployment (CI/CD), than GitHub. Testing and tracking production are built into GitLab and are supported by third-party apps with GitHub.
Corporate users might find GitLab providing more value, for use in say a Kubernetes environment. GitHub has traditionally catered more to the software development side of an organization. GitHub recently released their take on CI/CD in the form of Actions. You might take a look at it to see if it will work for your projects.
You might also look at the discussion of the major differences and similarities between GitLab and GitHub.
I found the GitLab web interface generally more complicated than GitHub. Both offer lots of features for more advanced git practitioners. GitLab extends functionality into testing and production, where GitHub, until recently, didn’t cover these as much. At login, both services take you right to your repositories, which is easy and painless for my basic project needs.