Want to shove a local project up to an already existing GitLab repository without performing ritual sacrifices to the command line gods? This guide walks you through the sane sequence of commands to create a local repo with git init
add files commit them and push to an existing GitLab repo. Optional SSH keys are included so you can stop typing your password like an amateur.
git init
git add
git commit
and git push
Make a directory for your project and drop in your code documentation or whatever sparks joy. If you forget a file right now you can add it later. For example on macOS or Linux:
mkdir my-project
cd my-project
# add your files or copy them in
Turn the folder into a Git repo with:
git init
git add .
git commit -m 'Initial commit'
That creates a local snapshot of your work. If your repo has a specific primary branch name use that name later when you push. Lots of projects use main
these days but some stubborn places still use master
or another branch name.
Get the remote URL from the GitLab project page then point your local repo at it. Replace REMOTE_URL
with the HTTPS or SSH URL shown by GitLab.
git remote add origin REMOTE_URL
# verify
git remote -v
Push the branch to GitLab. If your primary branch is main
run this:
git push -u origin main
If the remote expects master
or develop
change the branch name accordingly. The -u
or --set-upstream
option links your local branch to the remote branch so future git push
calls are simpler.
Open the GitLab project page and confirm the files landed where you expected. If you are working on a team set up branch protection rules merge request requirements and pipeline triggers as needed to match your DevOps workflow. That way nobody can push their way into chaos without passing a check.
If you do not enjoy typing credentials generate an SSH key and add the public key to your GitLab profile. A common modern choice is Ed25519.
ssh-keygen -t ed25519 -C 'your_email@example.com'
# then copy the public key
cat ~/.ssh/id_ed25519.pub
Paste that public key into GitLab under User Settings then SSH Keys. After that pushing over SSH does not ask for a password and life becomes marginally better.
git push
fails check your remote URL with git remote -v
and ensure you have permissions on the GitLab projectYou created a local project initialized Git added a remote and pushed code to an existing GitLab repository. You also learned how to set up SSH keys and where to look if things go sideways. Now go enjoy your slightly less annoying CI pipeline. Or at least pretend to.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.