how to set http as the project default url in gitlab

I stumbled over this problem while running several Gitlab accounts on the same machine which required different settings concerning the access protocol but every post I saw related to changes in the settings globally. To avoid configuration problems I looked for a way to change the settings for every project locally. Following steps fixed my problems:

  1. Open the terminal and change into your projects .git folder.

cd my_project/.git

  1. Open the browser. Navigate to the Gitlab repo. Click blue "Clone" button. Copy the URL for cloning via https.

  2. Switch to the terminal again. Edit the file named "config" located int the .git folder. I used "Vim" for editing.

vi config

  1. Change line with the existing url in the [remote "origin"] block to:

url = "paste copied url"


infact, you have to modify 2 other lines above the default_clone_protocol.

def default_url_to_repo(project = nil)
  project = project || @project
  current_user ? project.http_url_to_repo : project.url_to_repo
end

def default_clone_protocol
  current_user ? "http" : "ssh"
end

The app/views/shared/_clone_panel.html.haml file does show:

.git-clone-holder.input-group
  .input-group-btn
    %button{class: "btn #{ 'active' if default_clone_protocol == 'ssh' }", :"data-clone" => project.ssh_url_to_repo} SSH
    %button{class: "btn #{ 'active' if default_clone_protocol == 'http' }", :"data-clone" => project.http_url_to_repo}= gitlab_config.protocol.upcase

And that default_clone_protocol is defined in app/helpers/projects_helper.rb

def default_clone_protocol
    current_user ? "ssh" : "http"
end

So you could change that code, or add a setting in config/gitlab.yml.example in order to make it a parameter.

As mentioned by Mosi Wang's answer, the function default_url_to_repo also plays a role in the definition of that order, since it returns project.url_to_repo : project.http_url_to_repo.
Reversing the order can help too.

Tags:

Git

Gitlab