Git Snippets allows you to include pieces of code from your Git repository into Confluence pages.
On this page:
Git Snippets requires an Application Link in order work with Bitbucket Server. 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.
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.
With the Git snippet macro, you can insert code from Bitbucket Server or Github into a Confluence page.
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.
The line numbers will be extracted automatically from the URL, but you can change them afterwards at any time.
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.
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.
Download Git Snippets for Confluence
from the Atlassian Marketplace and
try it for free!