I am trying to push a newly created repository to gitlab. Here's what I did:
Create a project in gitlab. Example URL: https://gitlab.example.com/group1/project1.git
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 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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With