Git Notes

One-liners

Add files to an old commit

Edit an old commit

Rebase master onto a branch

$ git checkout master
$ git pull origin master
$ git rebase master <branch>
# Make manual changes as needed
$ git rebase --continue

Pushing a rebased branch to a remote will require --force:

$ git push origin <branch> --force

Extract part of a repo to a new repo

IMPORTANT: Start with a fresh clone of the repository, not your working copy

$ git reset --hard
$ git gc --aggressive
$ git prune
$ git clean -fd

Convert Remote CVS Repository to Git

$ git cvsimport -v -d <CVS repo path> <module>
# where CVS repo path is similar to
#    :pserver:anonymous@a.cvs.sourceforge.net:/cvsroot/pcal

Applying patches with git

$ git apply --reject --whitespace=fix <patch>
$ wiggle --replace <file> <file.rej>

Diff

Send patches by email

# Install and configure git-email
$ sudo dnf install git-email
$ git config --global user.name "My name"
$ git config --global user.email me@mail.com

# See https://git-send-email.io/
# and https://www.futurile.net/2022/03/07/git-patches-email-workflow/
[sendemail]
    smtpserver = smtp.gmail.com
    smtpencryption = ssl
    smtpserverport = 465
    smtpuser = jbru362@gmail.com
    smtpPass = !pass gmail/oauth

# Create the patch and send it
$ git format-patch -N # where N is the number of commits from HEAD to include
$ git send-email \
    --to maintainer@mail.com \
    --smtp-pass $(pass gmail/oauth | head -1) \
    <file.patch>
# Use the --annotation switch to edit the email
# Use the --dry-run switch to test
© 2021-2026 by Jeremy Brubaker. License: CC BY-NC-SA 4.0