Skip to content

My Short Path for Creating a Gitlab Project

Many times i want to quickly create a project in my Gitlab repo while creating new plugin/script for WordPress.

These command line instructions safe a lot of time by skipping the time to login, looking for changes in the interface, creating new project, selecting options (like remove the Readme at the beginning), etc. TBH i copied them from the Gitlab site just for my own purposes here. Like a notes.

You can also upload existing files from your computer using the instructions below.
Lets presume that you already have Git global setup and added a ssh key to your repo. Check this link if you got the message Permission denied – here

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git config --global user.name "Your name"
git config --global user.email "user@server.com"
git config --global user.name "Your name" git config --global user.email "user@server.com"
git config --global user.name "Your name"
git config --global user.email "user@server.com"

Create a new repository

If you start writing code and at a later stage you decide if it is worth uploading it to git repositories. Use only dash or underscores for the project names.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git clone git@gitlab.com:your-gitlab-user/project-name.git
cd project-name
git switch --create main
touch README.md
git add README.md
git commit -m "add README"
git push --set-upstream origin main
git clone git@gitlab.com:your-gitlab-user/project-name.git cd project-name git switch --create main touch README.md git add README.md git commit -m "add README" git push --set-upstream origin main
git clone git@gitlab.com:your-gitlab-user/project-name.git
cd project-name
git switch --create main
touch README.md
git add README.md
git commit -m "add README"
git push --set-upstream origin main

Push an existing folder (if you already have an empty project)

Sometimes i firstly create an empty Gitlab project first because i don’t remember the sequence and commands

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cd existing_folder
git init --initial-branch=main
git remote add origin git@gitlab.com:your-gitlab-user/project-name.git
git add .
git commit -m "Initial commit"
git push --set-upstream origin main
cd existing_folder git init --initial-branch=main git remote add origin git@gitlab.com:your-gitlab-user/project-name.git git add . git commit -m "Initial commit" git push --set-upstream origin main
cd existing_folder
git init --initial-branch=main
git remote add origin git@gitlab.com:your-gitlab-user/project-name.git
git add .
git commit -m "Initial commit"
git push --set-upstream origin main

Push an existing Git repository

I never tried this :)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cd existing_repo
git remote rename origin old-origin
git remote add origin git@gitlab.com:your-gitlab-user/project-name.git
git push --set-upstream origin --all
git push --set-upstream origin --tags
cd existing_repo git remote rename origin old-origin git remote add origin git@gitlab.com:your-gitlab-user/project-name.git git push --set-upstream origin --all git push --set-upstream origin --tags
cd existing_repo
git remote rename origin old-origin
git remote add origin git@gitlab.com:your-gitlab-user/project-name.git
git push --set-upstream origin --all
git push --set-upstream origin --tags

I will be happy if someone finds this article useful. Happy codding.

Views: 8

Leave a Reply

Your email address will not be published. Required fields are marked *