13

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
3
  • in that url, examples is your username Commented Mar 28, 2017 at 12:38
  • Sorry, examples is a group name. Let me edit that question. Commented Mar 28, 2017 at 12:39
  • I think all you can do is save your username somewhere but not the password. See git-scm.com/docs/gitcredentials Commented Mar 28, 2017 at 12:42

3 Answers 3

38

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.

Sign up to request clarification or add additional context in comments.

3 Comments

how to replace '&' symbol from my password ?
'&' I believe is 26, try %26 - not verified
On gitlab.com the colon had to be changed to a slash to get it to work: https://user:[email protected]/group/project.git
4

If you get fatal: remote origin already exists error. Check what origin is set up and remove it

git remote -v
git remote rm origin

Add remote origin for https. You can set up username:password in url but credentials will be seen plain text in git remote -v

git remote add origin https://username:[email protected]/group1/project1.git
git remote -v
git push -u origin --all
git push -u origin --tags

I need to use \ after url and before group instead of :, otherwise I get an error URL using bad/illegal format or missing URL.

If you have special characters in password and get an error bash: !: event not found, for example, for '!' use '%21' (google for 'HTML URL encoding reference').

It is possible to add remote without credentials in url

git remote add origin https://gitlab.example.com/group1/project1.git
git config credential.helper store
git config --list

it will prompt for credentials on first login and should not afterwards. store option stores credentials same in plain text in ~/.git-credentials. On Windows to store credentials in "Credential Manager"

 git config credential.helper wincred

you can delete ~/.git-credentials then. To clear credential helper

git config credential.helper ""

Comments

3

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.