DEV Community

rndmh3ro
rndmh3ro

Posted on • Originally published at zufallsheld.de on

TIL how to upload files to Gitlab snippets from the CLI

I recently wanted to share a code-snippet with a colleague. I decided to use Gitlab Snippets for this. However the snippet was more of some hundred lines of code in a text-file which I didn’t want to simply copy-paste.

Lucky for me I had python-gitlab installed, a Python library and CLI-tool to interact with Gitlab instances.

# Copy the contents of an existing file (readme.md) into a new snippet with the title "title" and filename "readme.md":
> gitlab snippet create --title "title" --file-name "readme.md" --content "$(cat readme.md)"
id: 36
title: title

# Update the snippet with new contents
> gitlab snippet update --id 36 --title "title" --file-name "readme.md" --content "$(cat new_readme.md)"

Enter fullscreen mode Exit fullscreen mode

Top comments (0)