roschach
roschach

Reputation: 9336

How to push to a newly created project in gitlab

I have created a new namespace and project in gitlab from the terminal with the command

git remote add origin https://gitlab.com/nameSpace/projectName

but when I try to push it with the command

push -u origin master

I get the error

fatal: unable to update url base from redirection:
  asked for: https://gitlab.com/nameSpace/projectName/info/refs?service=git-receive-pack
   redirect: https://gitlab.com/users/sign_in

I tried also the option --set-upstream as suggested in gitlab documentation but it did not solve.

The project and master branch should have been created because when I try to remote add it tells me origin-master already exists. However using the browser I cannot see any project folder.

Many of the questions on SO were solved by adding -u but it did not work in my case.

How to push files to a newly created project in gitlab?

Upvotes: 2

Views: 2498

Answers (2)

mmh
mmh

Reputation: 63

The error message suggests that you are not logged in (as it is redirecting you to signin). You should try the same command by providing your credentials.

As per Gitlab documentation, you could do the following to create a project (within namespace) as follows,

## Git push using SSH
git push --set-upstream [email protected]:namespace/nonexistent-project.git master

## Git push using HTTPS
git push --set-upstream https://gitlab.example.com/namespace/nonexistent-project.git master

The documentation doesn't mention about adding 'origin'. So may be you should remove that and try it.

Upvotes: 0

S.K.
S.K.

Reputation: 3677

You can also try ssh authentication:

  1. Replace https origin url to ssh by:

    git remote rm origin
    git remote add origin <ssh-path-for-your-project>
    
  2. Generate ssh key for your system by ssh-keygen
  3. Add the generated ssh key to your profile from gitlab portal
  4. Try to push now

Upvotes: 2

Related Questions