Git

How to Push to GitLab

On large development projects in Git, users often work with different modules on their local repositories, and through this facility, the physical appearance is not required. Once the module is completed, it is necessary to push it to GitLab remote host for merging with other project modules. For that corresponding purpose, they can use the “git push” command.

In this blog, we will provide the easiest way to push the local repository changes into GitLab.

How to Push Local Changes into the GitLab?

Check out the provided procedure to push the local repository into the GitLab remote repository:

    • Redirect to the preferred local repository.
    • List the current repository content.
    • Add the remote URL by running the “git remote add” command.
    • Execute the “git push <remote-name> <branch-name>” command.

Step 1: Redirect to the Local Repository

Move to the local repository by running the following command:

cd "C:\Users\nazma\Git\Git\demo1"

 
Step 2: List Repository Content

Then, run the “ls” command to list all the existing content:

ls

 
As you can see, our current local repository contains five text files that we want to push into the GitLab:


Step 3: List Remote URL

Then, check the remote name and URL by running the following command:

git remote -v

 
According to the provided output currently, no remote URL has been specified for tracking:


Step 4: Copy Remote URL

To set the remote URL, navigate to the GitLab remote repository, and copy its URL:


Step 5: Set Remote URL

After doing so, redirect to the Git utility, run the below-given command with the new remote name, and copied the remote URL:

git remote add origin https://gitlab.com/devteam5985925/Demo1.git

 

Step 6: Verify Added Remote URL

To check whether the remote URL has been added or not, use the “git remote -v” command:

git remote -v

 

Step 7: Push Local Changes into GitLab

Finally, push the local machine changes into the remote server by running the “git push” command with the remote name as “origin” and “master” as a branch:

git push origin master

 
According to the following output, our local changes have been added to the GitLab repository:


We have compiled the easiest way to push local changes into GitLab.

Conclusion

To push local machine changes into the GitLab remote repository, first, move to the preferred repository and list the content which needs to be pushed. Then, set the remote URL if not added yet by running the “git remote add” command along with the remote name and URL. Lastly, run the “git push <remote-name> <branch-name>” command. This tutorial elaborated on the push to GitLab.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.