← All examples

Action Developer & QA gitlab.com

GitLab: copy the branch name

Copies the current branch or merge-request source branch name to the clipboard with a short confirmation.

Code to copy

// Copy the current branch or merge-request source branch to the clipboard
const el = document.querySelector(
  '.ref-name, [data-testid="ref-name"], .js-source-branch, .source-branch-name'
);
const name = el ? el.textContent.trim() : '';
if (name && navigator.clipboard) {
  navigator.clipboard.writeText(name).then(function () {
    const note = document.createElement('div');
    note.textContent = 'Branch copied: ' + name;
    note.style.cssText =
      'position:fixed;bottom:20px;left:50%;transform:translateX(-50%);' +
      'background:#1f1f1f;color:#fff;padding:8px 14px;border-radius:6px;z-index:9999;font-size:13px';
    document.body.appendChild(note);
    setTimeout(function () { note.remove(); }, 2000);
  });
}

How to use this example

  1. Copy the code with the button above.
  2. Install JustZix (2 minutes) and open the extension on the target page.
  3. Add a new rule matching that page.
  4. Enable the action panel, add a button in the Actions tab and paste the code into it — run it with one click.

Rate this example

No ratings yet — be the first.

Does this example work?

Snippets are useless without somewhere to paste them.

JustZix takes 2 minutes to install and runs your code on every matching page. No account, no payment.

Download free See use cases