What is Git?
Git is open-source software that is designed to track changes in everything, from small to large projects with high speed and efficiency. It is a version control system usually used by developers/programmers for work collaborations while developing source code during software development.
In this guide, you will see how you can push a project from your local machine to GitLab. For this, you need git installed and configured on your local machine. We are using Linux Mint 20 as the operating system in our local machine. You also need to have a GitLab account to push your project.
With further ado, let’s get started!
Step 1: Create an empty project
First of all, let’s create an empty project in our local machine. I have created a My Projects directory on the desktop. In this directory, I will be creating a project here to push to GitLab.
Inside Myprojects, I have created a project with the name Project1. This is the project I will push to GitLab.
Step 2: Open Project directory in terminal
Now, open your terminal and go to the project’s directory with the cd command.
cd “project’s path”
Step 3: Initialize project
Now that you are inside the project, initialize the project using the following command:
After this, your project repository will be initialized and you will get the following confirmation:
This means that now your project will be able to be tracked with git. You will also see a .git folder after initialization. If you cannot see it, go to view and tick the view hidden files box. Now you will be able to see it.
Step 4: Check project’s status
Check the status of your repository by running the following command:
It will tell you which branch you are on. We are on the “master” branch. And there are no commits yet. This means that there are no changes or files in the project to be committed.
Step 5: Create an empty file in project directory
Next, I will create an empty file “Text.txt” in “Project1” directory.
Step 6: Check the status
Now if I check the status of the project, it will show a file that is untracked that we just created.
Step 7: Add file to git
To add this file to git, run the command:
git add filename
git add Text.txt
Let’s check the status of the project with the command we used before. Now, it is showing the file in green which means the file has been added in git. Now it is ready to be committed.
Step 8: Commit changes
Now to commit our changes, we will use the following command:
git commit -m "msg”
In the message, you can write something meaningful that everyone can follow.
After running the command, you will see a confirmation that your commit is done.
Step 9: Copy clone URL
Now go to your GitLab account, and go to the project.
Inside it, you will see no changes. That is because we have only committed our changes but have not yet pushed them to GitLab. To push the changes, go to clone and copy “clone with https” URL. I will show it in the next step.
Step 10: Push the changes
To push the changes to GitLab, run the command mentioned below. In place of origin, give the URL you copied in the previous step. Replace branch with the name of the branch in the syntax mentioned below. In my case, it is “master”.
git push origin branch
After running the command, you will be asked to type your username of GitLab account, as well as your password to get access.
With the right credentials, you will get access and the repository changes will be pushed to GitLab. You will get the following confirmation:
Now go to your GitLab account, and open the project. You will now see changes that you made in the local repository.
That was all, guys.
In this detailed guide, you saw how to push changes in our local project repository to GitLab with the help of a few easy-to-follow git commands. Like this, you can collaborate with your fellow developers for work without running into errors.
To see how you can install and configure Git on Linux Mint 20, visit: