๐ GitLab: From Local Folder to Remote Repoยถ
๐ Initialize a Local Repositoryยถ
Navigate to your project folder in the terminal
cd /path/to/your/folder git init
This makes your folder a Git repository, then add your files and make the first commit:
git add . git commit -m "Initial commit"
๐ Connect Local Repo to GitLabยถ
On the GitLab project page, copy the repo URL:
HTTPS example:
git remote add origin https://gitlab.com/username/my-project.git
SSH example (recommended):
git remote add origin git@gitlab.com:username/my-project.git
๐ Push to GitLabยถ
git branch -M main # Ensure branch is called main
git push -u origin main
- Your project is now on GitLab ๐
โก Fixing the README Conflictยถ
If you created your GitLab repo with a README, youโll see this error when pushing:
fatal: refusing to merge unrelated histories
Solution: Merge histories
git pull origin main --allow-unrelated-histories
- Resolve conflicts if prompted.
Then push again:
git push -u origin main
Alternative: Overwrite remote (โ destructive)
git push -u origin main --force
- Only use this if you donโt need the GitLab README or other remote history.
๐ ๏ธ Common Git Commands Cheat Sheetยถ
Check repo status
git statusSee commit history
git log --oneline --graph --all
Pull latest changes
git pullStage & commit changes
git add . git commit -m "Your message" git push
โ Summaryยถ
git initโ create local repogit add .&&git commit -m "Initial commit"โ commit files- Create GitLab project
git remote add origin <repo_url>โ connect remotegit push -u origin mainโ upload files- Set up SSH for easier pushes
- Use
--allow-unrelated-historiesif GitLab created a README