GitLab Repository

1️⃣ Initialize a New Repository

#Can be create a new one from GitLab UI but these steps help us to create from our local terminal.
#For these steps, GitLab token is a must. If you don’t have a token yet, you’ll need to create one manually from GitLab > Settings > Access Tokens.

Navigate to the folder where you want to create your project and run:

mkdir my-project && cd my-project
git init


Expected Output:

Initialized empty Git repository in /home/user/my-project/.git/

2️⃣ Add a File to the Repository

Create a simple file (like README.md) to track:

echo "# My GitLab Project" > README.md
git add README.md
git commit -m "Initial commit"

3️⃣ Create a Repository on GitLab via API

Now, run this command to create a repo on GitLab using their API (replace your-access-token with your GitLab Personal Access Token):

curl --header "PRIVATE-TOKEN: your-access-token" -X POST "https://gitlab.com/api/v4/projects?name=my-project"

Copy the "ssh_url_to_repo" from the response.

4️⃣ Link Your Local Repository to GitLab

Run this command, replacing the URL with your repository’s SSH URL:

git remote add origin git@gitlab.com:your-username/my-project.git
git branch -M main
git push -u origin main

Now, your local repository is linked to GitLab, and you can start pushing changes! 🎉

Next step is –> Make Changes and Push to GitLab

For more details : https://docs.gitlab.com/user/project/repository/

Scroll to Top