Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you clone GitLab snippets?

Tags:

git

gitlab

It's easy enough to create them, but I can't find out how to clone them and edit offline.

Is it possible?

like image 377
EmilioAK Avatar asked Nov 25 '15 00:11

EmilioAK


People also ask

Can you git clone from GitLab?

After you successfully clone the GitLab repository, navigate into the newly created gitlab-made-easy folder. Inside you will see a README file, which verifies that the clone operation was successful.

What is GitLab snippet?

With GitLab snippets, you can store and share bits of code and text with other users. You can comment on, clone, and use version control in snippets. They can contain multiple files. They also support syntax highlighting, embedding, downloading, and you can maintain your snippets with the snippets API.

How do I clone code from GitLab to Visual Studio?

To clone the project, use the official Git: Clone command and select your GitLab instance. Use the Git: Clone command by selecting the command from the Command Palette. This feature can save you time if you already know the name of the project you want to clone. VS Code lets you filter which project to clone.


2 Answers

May 2020, for GitLab 13.0: yes!

Versioned Snippets

Snippets are useful for sharing small bits of code and text that may not belong in the main project’s codebase.

These items are important to groups and users who rely on them for other tasks, like scripts to help generate diagnostic output or setup supporting services for testing and demo environments.

Unfortunately, a lack of version control has made it hard to know if a snippet was the latest version or what changes may have happened and how to reconcile those.

Snippets in GitLab are now version controlled by a Git repository.

https://about.gitlab.com/images/13_0/phikai-versioned-snippets.png

When editing a Snippet, each change creates a commit. Snippets can also be cloned to make edits locally, and then pushed back to the Snippet repository.

This is the first step in enabling more collaboration on Snippets.
In future releases we’ll introduce support for multiple files, continue to expand features and expand permissions.

See documentation and issue.


And with GitLab 13.5 (October 2020):

Snippets with multiple files

Engineers often use Snippets to share examples of code, reusable components, logs, and other items. These valuable pieces of information often require additional context and may require more than one file. Sharing a link to multiple files or multiple Snippets makes it challenging for users to piece this context together and understand the scope of what is being presented.

In GitLab 13.0, we laid a foundation for Snippets by giving them version control support based on a Git repository. Version control and the history it provides are an important piece of context when looking at code and understanding its purpose, but it may not be everything.

GitLab now supports multiple files inside of a single Snippet, so you can create Snippets composed of multiple parts. It broadens its use to endless possibilities. For example:

  • A snippet that includes a script and its output.
  • A snippet that includes HTML, CSS, and JS code, from which the result can be easily previewed.
  • A snippet with a docker-compose.yml file and its associated .env file.
  • A gulpfile.js file coupled with a package.json file, which together are used to bootstrap the project and manage its dependencies.

Providing all of these files in a single Snippet gives more options for the types of content that can be shared and the context that is provided when looking at them. We’re excited to see the types of content you will create and share using Snippets with multiple files!

https://about.gitlab.com/images/13_5/phikai-snippets-multiple-files.png -- Snippets with multiple files

See Documentation and Issue.


2015: original answer: Not directly.

Gitlab already have snippets section under each project.
Like: http://gitabhq.com/project-name/snippets/

But it is not available for cloning.

There was a request for a GitHub Gist-like feature for GitLab (based on Gistie), also asked in GitLab suggestions.
But that was not implemented at the time.


Update 2019, as commented by eli, and documented in "Downloading snippets" (GitLab 10.8+)

For now its just possible to download snippets, e.g.

https://gitlab.com/snippets/SNIPPET_ID/raw?line_ending=raw – 
like image 191
VonC Avatar answered Oct 23 '22 05:10

VonC


You can clone by ID like this

for i in $(seq  1 100); do git clone git@gitlab_url:snippets/"$i".git; done
like image 33
David Hrbáč Avatar answered Oct 23 '22 05:10

David Hrbáč