Skip to content

Instantly share code, notes, and snippets.

@grafov
Created July 17, 2025 18:29
Show Gist options
  • Save grafov/6ca754d47590dd972e35e41de56739fe to your computer and use it in GitHub Desktop.
Save grafov/6ca754d47590dd972e35e41de56739fe to your computer and use it in GitHub Desktop.
Backup current Git branch with predefined name based on the date.
(defun my-magit-backup-branch ()
"Backup current Git branch with predefined name based on the date."
(interactive)
(let* ((current-branch (magit-get-current-branch))
(branch-name (format "backup-%s-%s" current-branch (format-time-string "%y-%m-%d-%H-%M" (current-time)))))
(magit-run-git "branch" "-d" branch-name)
(magit-run-git "checkout" "-b" branch-name current-branch)
(magit-run-git "push" "--force" "origin" branch-name)
(magit-checkout current-branch)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment