Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitlab - push using https, specifying username & password

Tags:

git

gitlab

I am trying to push a newly created repository to gitlab. Here's what I did:

  1. Create a project in gitlab. Example URL: https://gitlab.example.com/group1/project1.git

  2. Initiated a local bare repo:

    cd ~/projects
    git init --bare ./project1.git
    cd project1.git
    

Question:

Next step is to push all of my local repo into gitlab. But I want to specify username and password using https. How do I change the following to do it?

git remote add origin https://gitlab.example.com:group1/project1.git
git push --all
git push --tags
like image 763
code4kix Avatar asked Mar 28 '17 12:03

code4kix


Video Answer


2 Answers

Like others mentioned here, ssh is preferred. But for those you want to use just http/https, you can specify credentials like this:

git remote add origin https://username:[email protected]:group1/project1.git

Verified for gitlab 9.0

Note: Please replace '@' symbols in username with '%40' to work this.

like image 149
code4kix Avatar answered Oct 07 '22 01:10

code4kix


When you created the repo in gitlab, by deafault it will provide to clone git repo using two protocols, ssh and https. Where in https it will prompt your user credential every time you pull or push.

I prefer to use ssh. Where as in ssh you can push lot of files to repo. In https you have size restriction. Perhaps you want push 4gb files to repo.

Follow these steps to set ssh as remote:

git remote rm https://gitlab.example.com:group1/project1.git

git remote set-url origin ssh://user@host:1234/srv/git/example

Useful information:

Worth reading about setting up git remote:

https://help.github.com/articles/changing-a-remote-s-url/

like image 24
danglingpointer Avatar answered Oct 07 '22 01:10

danglingpointer