gitlab - Push to a repository using access_token

扶醉桌前 提交于 2019-12-03 12:27:46

问题


I implemented the oauth2 web flow in order to get access_token from users of my app.With the access_token, I would like to do the following actions:

  • 1. Get user informations
  • 2. Create a repo for this user
  • 3. Push code to this repo (using git push )

I already successfully get the user informations(1) and create a repo(2)

The problem is I can't push code (3), I got "Unauthorized" error.


The command I run:

git remote add origin https://gitlab-ci-token:<mytoken>@gitlab.com/myuser/myrepo.git
git push origin master
Best regards.


回答1:


You should do

git remote add origin https://oauth2:<mytoken>@gitlab.com/myuser/myrepo.git



回答2:


It is also possible to push directly without adding a new remote repository:

git push https://gitlab-ci-token:<access_token>@gitlab.com/myuser/myrepo.git <branch_name>

This could be especially handy if you would like pull & push to different repositories.




回答3:


Push using gitlab-ci-token is not currently supported by Gitlab. There is an open feature request.



来源:https://stackoverflow.com/questions/42074414/gitlab-push-to-a-repository-using-access-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!