Git Snippets allows you to include pieces of code from your Git repository into Confluence pages.
Bitbucket Server Requirements
Git Snippets requires an Application Link or an Access Token in order work with Bitbucket Server. Note: If both an Application Link and an Access Token are configured for a Bitbucket Server instance, your users will be able to choose between the two in the Git Snippets macro.
Go to the Confluence Administration → Application Links an follow the Documentation to create an Application Link to Bitbucket. After that, the users will get an one-time authorization message when they want to see or add a Git snippet if they haven't authorized Bitbucket yet.
If you can't create an Application Link to your Bitbucket Server instance, or want to make Git Snippets available for anonymous users, you can also configure a Bitbucket Server access token. To make Git Snippets use a such a token, you need to go to your Bitbucket instance Manage Account → Personal Access Tokens and create one. Then go to Confluence Administration → Git Snippets Settings and insert your token together with the address of your Bitbucket Server instance.
Bitbucket Cloud Requirements
No steps are required to use public repositories from bitbucket.org.
For private repositories you need to add a Bitbucket username and app password. Log in to bitbucket.org and go to Settings → App Passwords. Create a new password and check the Read permission for repositories.
Copy the generated password and go to Confluence Administration → Git Snippets Settings and insert your username and app password in the Bitbucket.org section.
In order for Git Snippets to work with Github, you need a Github account with which the Git Snippets macro will make the requests to get the code from Github. Git Snippets will need a personal access token, you can create with your Github account. Then go to Confluence Administration → Git Snippets Settings and insert your token.
Git snippet macro
With the Git snippet macro, you can insert code from Bitbucket Server or Github into a Confluence page.
Inserting a snippet
To add a snippet, browse to a file in the web frontend of Bitbucket Server or Github, select the lines you want to display in Confluence (if you don't select the lines, the whole file will be displayed) and copy the URL.
Then go to a Confluence page, add the Git snippet macro and paste the URL you just copied.
You should now see the selected code as a snippet in the macro preview. Click Save to insert the macro.
Updating the line numbers
The line numbers will be extracted automatically from the URL, but you can change them afterwards at any time.
Updating the commit hash
The commit hash is automatically inserted when you paste an URL. When the code changes in the repository, the commit hash will differ from the one stored in the macro and Git snippets will try to show the correct snippet. even though the line numbers might have changed. You can update to the latest commit by clicking Load latest commit.
Enabling the Markdown Renderer
If the snippet you are including is a Markdown file, you can choose to render it directly as HTML instead of displaying the Markdown as a code block. Settings like "Theme" and "Line Numbering" will affect the code blocks that are generated from that snippet.
Git snippet guide blueprint
With the Git snippet guide blueprint, you can create step-by-step guides with Git snippet macros.
For example, you can use real code to document how to create a Confluence macro by pointing out the necessary steps like updatinh the plugin XML, creating a class, etc.