Why Use GitLab?
- Centralized source code management
- Built-in CI/CD pipelines
- Issue tracking and project management
- Team collaboration and code reviews
- 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
- Sign in to GitLab.
- Click New Project.
- Enter the project name.
- 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.