REST-full access: Cannot add file to repository in Gitlab
Question
I tried the following request:
curl -v -X POST --header "PRIVATE-TOKEN:myPrivateToken" 'url-of-gitlab/api/v3/projects/myProjectId/repository/files?file_path=1.json&branch_name=master&content=thefilecontent&commit_message=ACommitMessage'
However, I invariably get
"message":"You can only create files if you are on top of a branch"
in the response. I don't know what's missing from my request. The repository is newly created and I created it through the Gitlab UI. Maybe I need to create a branch first? Any help would do. Thank you very much.
Solution
The repository is newly created and I created it through the Gitlab UI.
A newly created repo (through GitLab or even a simple git init
locally) has no branches (and no HEAD).
This is what I describe in "Why do I need to explicitly push a new branch?".
Maybe I need to create a branch first?
Yes, you do (at least a master
branch)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow