Sign up
  • Home
  • Productivity
  • App tutorials

How to Push to GitLab

App tutorials

3 min read

How to Push to GitLab

By Khamosh Pathak · June 10, 2019
how-to-push-to-gitlab primary img

To get started with GitLab, you'll need to create a repository and push code to it. Here's how to push to GitLab.

How to Create a Project (Repository) in GitLab

Because of their larger potential in GitLab, repositories are called projects. But you can use the words interchangeably because a project behaves the same way as a repository you might find on GitHub.

After creating your account in GitLab, go to your Projects page and click New project.

Blank project page in GitLab

From the Blank project tab, give the project a name and add a description. If you want it to be a public repository, click the Public option. Make sure the Initialize repository with README option is left unchecked. Then click the Create project button.

How to Push to GitLab

Once a new project is created, it will be blank by default. There are a couple of ways to populate it. You can directly add files online using the Add Files button.

But if you're going to be using GitLab as an online versioning tool, it's best to upload your local project files using the command line. To get started, first install and set up Git on your Linux, Mac, or Windows PC.

Then, open the Terminal (Git Bash on Windows) and navigate to the local folder that you want to sync with your GitLab project. Use the cd command to switch to the folder in question.

Now you can start the Git process with this command:

git init

git init

Now you'll connect the remote GitLab project with your local directory. Use the following command, pasting in your GitLab project URL at the end (make sure it ends in .git).

git remote add origin <project link>

git remote add origin

After you press Enter or Return, you won't see any confirmation. That's because you haven't added or transferred the files to the Git process yet. To add all the files from the current directory to the Git process, use the following command.

git add .

Then you can check if all files were added correctly using the following command.

git status

git status check

Now you'll make a commit, so you know which files were included when the local directory was first uploaded to the GitLab project. You can add your comment between the quotes at the end of the next command. It can include what changes you made recently to the code and if you added any new files.

git commit -m "first commit"

first commit

Now you're ready to actually push the files and code to GitLab. Enter the following command.

git push -u origin master

origin master

After you press Enter or Return, you'll be asked to enter your GitLab username and password. Since you've created a private repository, this step makes sure that only the project owner can make changes to the repository.

Once the authentication is done, the upload process will begin. And shortly, you'll see a message saying that the upload is finished.

To check whether all the data was uploaded properly, you can open the project in your browser. Instead of the blank page, you'll now see a list of all the files and folders in the project.

alt

Automate GitLab with Zapier

Zapier lets you connect GitLab to thousands of apps, so you can automate more of your Git processes.

  • For example, you could automatically get a notification or create a task in your project management tool whenever there's a new merge request in your repo.

  • Or you could create a new issue in GitLab whenever you get a relevant email or move a Trello card to a specific status.

Head to our GitLab integrations page for more ideas on how to supercharge GitLab.

Get productivity tips delivered straight to your inbox

We’ll email you 1/wk, and never share your information.

Khamosh Pathak picture

Khamosh Pathak

Khamosh Pathak is a technology writer specializing in simplifying consumer technology for the everyday user. He’s on a mission to help users get the most out of their technology products, whether it’s hardware or software.

tags
mentioned apps

Related articles

Improve your productivity automatically. Use Zapier to get your apps working together.

Sign upSee how it works