GitLab
This guide shows how to initialize a Git repository locally and push it to a GitLab project.
Create a project on GitLab
- Log in to your GitLab account.
- Click + .
- Choose New project/repository.
- Fill in the project name and other details.
- Create the project.
Initialize local repository
Navigate to your project folder:
cd /path/to/your/project && git init
Add remote repository
git remote add origin https://gitlab.com/username/project.git
Replace the URL with your actual GitLab project URL.
Pull README if it exists
git pull origin main
Stage and commit changes
Add all files:
git add .
Check status:
git status
Commit changes with a message:
git commit -m "Commit message"
Push to GitLab
First push (sets upstream):
git push -u origin main
-u stands for --set-upstream. It tells Git that your local main branch corresponds to main on origin.
Once upstream is set, you can just run:
git push
View commit history
git log