DEV Community

Adhi sankar
Adhi sankar

Posted on

GitLab Commands and How to Push Code on GitLab

Why Use GitLab?

  1. Centralized source code management
  2. Built-in CI/CD pipelines
  3. Issue tracking and project management
  4. Team collaboration and code reviews
  5. Secure repository hosting

Common Git Commands

Check Git Version

git --version

Configure Git Username and Email

git config --global user.name "Your Name"
git config --global user.email "your@email.com"

Initialize a Repository

git init

Check Repository Status

git status

Add Files

Add a single file:
git add filename
Add all files:
git add .

Commit Changes

git commit -m "Initial commit"

View Commit History

git log

How to Push Existing Code to GitLab
Step 1: Create a Project in GitLab

  1. Sign in to GitLab.
  2. Click New Project.
  3. Enter the project name.
  4. Click Create Project.

Step 2: Open Terminal in Your Project Folder

cd your-project-folder

Step 3: Initialize Git

git init

Step 4: Add Files

git add .

Step 5: Commit Files

git commit -m "First commit"

Step 6: Connect Local Repository to GitLab
Replace the URL with your GitLab repository URL:

git remote add origin https://gitlab.com/username/project-name.git

Step 7: Push Code to GitLab
For a new repository:

git branch -M main
git push -u origin main

Daily Workflow Commands

git add .
git commit -m "Updated project"
git push

Conclusion

GitLab combined with Git provides a complete platform for version control and collaboration. By learning basic Git commands such as git add, git commit, and git push, developers can efficiently manage code and keep projects synchronized with GitLab repositories. Following a consistent Git workflow improves productivity, code quality, and team collaboration.

Top comments (0)