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

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more