Merge and rebase

# rebase interactively all commits on this-branch
git rebase -i $(git merge-base this-branch main)

Undo changes and commits

# Remove last commit from staging
git restore --staged <filename>

# Undo all changes
git restore filename
git checkout -- filename

# undo last two commits
git reset HEAD~2

# Reset takes these options: --soft, --mixed, --hard

# soft undoes the commit, but keeps the changes in the staging area
# soft undoes the commit, but keeps the changes in the working dir
# hard undoes everything

More

# Limit commands to a range
git blame -L 15,26
git log -L 15,26 file-path

# Commits that changed specified pattern
git log -S pattern

# Remember and repeat merge resolutions
git config --global rerere.enabled true

# Safer push
git force -with-lease

Gitlab

# push without triggering a pipeline run
git push -o ci.skip

# create a merge request automatically
git push -o merge_request.create

# empty commit e. g. to trigger a build
git commit --allow empty -m 'it works!'