Setelah menggunakan 2FA (Two-factor authentication) di Gitlab, user tidak bisa lagi langsung menggunakan URL https://gitlab-url/NAMA/repository.git untuk cloning ataupun push, contoh

git clone https://gitlab.jaranguda.com/tommy/gateway.git
Password for 'https://[email protected]': 
remote: HTTP Basic: Access denied
remote: You must use a personal access token with 'read_repository' or 'write_repository' scope for Git over HTTP.
remote: You can generate one at https://gitlab.jaranguda.com/profile/personal_access_tokens

Solusi

ada dua langkah untuk mengatasi masalah diatas.

1. Generate token user

Buka https://gitlab-url/profile/personal_access_tokens, buat token baru, yang perlu diisi

name
read_repository
write_repository

kedua permission tersebut dibutuhkan agar yang menggunakan token bisa membaca/tulis kedalam repository.
generate user cli
klik Create Personal Token
personal token access gitlab
copy personal access token tersebut, contoh diatas JRcpp_yV-gVLbc9o8H1R, code tersebut hanya ditampilkan sekali.

2. Buat Format URL

Bila sebelumnya anda menggunakan

git clone https://gitlab.jaranguda.com/tommy/gateway.git

ubah menjadi format https://oauth2:PERSONAL-ACCESS-TOKEN@URL-GITLAB/USER/repository.git

git clone https://oauth2:JRcpp_yV-gVLbc9o8H1R@gitlab.jaranguda.com/tommy/gateway.git

untuk repository yang telah di buat sebelumnya. Pindah ke folder project anda (contoh /home/jaranguda/git/gateway), lalu ubah file .git/config pada bagian URL

[core]
      	repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = https://gitlab.jaranguda.com/tommy/gateway.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

menjadi

[core]
      	repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = https://oauth2:JRcpp_yV-gVLbc9o8H1R@gitlab.jaranguda.com/tommy/gateway.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

pengaturan ini hanya untuk yang menggunakan https, untuk yang menggunakan SSH, biasanya dengan format git@URL/USER/REPOSITORY.git tidak perlu dilakukan perubahan.

Leave a comment

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