Configuration

Rewrite history (rebase -i) with VSCode

A rebase with VSCode does not work, as the editor window is immediately closed and the command is ended. Unless you add this to your config.

[sequence]
  editor = code --wait --reuse-window

Aliases

Here are some aliases that I want to remember.

Squash-commits

I have two commits and thing they should be one. The message of the last commit is used for the new commit.

[alias]
  squash-commits = "!_() { rev=$(git log -1 --pretty=%B) && git reset --soft HEAD~2 || exit 1 ; git commit -m \"$rev\"; }; _"

Flip-commits

I would like to add a change to a commit, but unfortunately it is not the last one, it is the second last. Therefore, I flip them on a detached HEAD. Cherry pick the last of the original branch. Branch the detached HEAD to a Branch named temp/flip-commits. Switch to the original branch. Reset the branch to the third last commit. Rebase the temp/flip-commits branch. And finally delete the branch named temp/flip-commits.

[alias]
  flip-commits = "!_() { rev1=$(git rev-parse @~) && rev2=$(git rev-parse HEAD~2) && rev3=$(git rev-parse --abbrev-ref HEAD) && git rebase --onto HEAD~2 HEAD~1 HEAD || exit 1 ; git cherry-pick $rev1 && git branch temp/flip-commits && git checkout $rev3 && git reset --hard $rev2 && git rebase temp/flip-commits && git branch -d temp/flip-commits; }; _"

Clean-branches

I want to clean up my branches even when PRs are squashed into a single commit and fetch --prune does not work.

[alias]
  clean-branches = "!f() { git branch | grep -v \"hotfix\\|release\\|research\\|main\\|master\\|develop\\|*\" | xargs git branch -D; }; f"