×


Push a Project to Remote GitLab Using Git on Linux Mint 20

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.

Here at Ibmi Media, we shall look into how you can push a project from your local machine to GitLab. To implement this, you need git installed and configured on the Linux Mint 20 machine. 

You also need to have a GitLab account to push your project.

To see how you can install and configure Git on Linux Mint 20, visit: https://linuxapt.com/blog/1200-install-and-configure-git-on-linux-mint-20


Steps to push a project from your local machine to GitLab

1. Create an empty project

To begin, We will create an empty project in our local machine. We have created a My Projects directory on the desktop. In this directory, We will be creating a project here to push to GitLab.

Inside Myprojects, We have created a project with the name Project1. This is the project We will push to GitLab.


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"
$ cd /home/azifa/Desktop/Myprojects/Project1


3. Initialize project

Now that you are inside the project, initialize the project using the following command:

$ git init

After this, your project repository will be initialized and you will get a 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.


4. Check project's status

Check the status of your repository by running the following command:

$ git status

Now you will know 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.


5. Create an empty file in project directory

Next, We will create an empty file "Text.txt" in "Project1" directory.


6. Check the status

Now if We check the status of the project, it will show a file that is untracked that we just created:

$ git status


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:

$ git status


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.


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.


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 our 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.

Now go to your GitLab account, and open the project. You will now see changes that you made in the local repository.


[Need help in fixing Git issues ? We can help you. ]


Conclusion

This article covers how to push changes in our local project repository to GitLab with the help of a few easy-to-follow git commands. In fact, you can collaborate with your fellow developers for work without running into errors.


More about GitLab repository

In GitLab, files are stored in a repository. In GitLab, a repository is contained in a project. A repository is similar to how you store files in a folder or directory on your computer:

  • A remote repository refers to the files in GitLab.
  • A local copy refers to the files on your computer.
  • Often, the word “repository” is shortened to "repo".