Some Git Tips useful for contributors and developers

Here we put some tips and cheatsheets, the full documentations are at Git Primer in Committer's Guide and Using Git in Handbook, which is recommended to read and editing is always welcomed.


There are two common places for git config, global (~/.gitconfig) and project wise (/path/to/the/project/.git/config).

You can set your preferred name and email for different projects:

        name = 
        email = 

Please note, that email set in the global user config (~/.gitconfig) will get used in all repositories that do not set per repo value.


To show both for author and committer information for checking the credit is given to the submitter, set fuller format for git log and git show

        pretty = fuller

dealing with pgp keys

When updating pgp keys in the handbook, it's helpful to be able to confirm what actually changed to your key before committing.

Consider adding this stanza to your $HOME/.gitconfig:

[diff "gpg"]
        textconv = "f(){ gpg --list-packets < \"$1\" | grep -v \"^# off=\"; }; f"

and this to /path/to/your/doc-repo-clone/.git/info/attributes:

*.key diff=gpg

When you now "git diff" or "git show" in the doc repo, the base64 encoded blobs will be decoded to (slightly) more readable PGP packets.

rewriting history

To rewrite history, including separating out components from FreeBSD src, see the examples in git-filter.

commit count (replacement of revision number)

git rev-list --first-parent --count HEAD

Show your diff while writing commit msg

If you want to see your uncommitted diff while writing a commit message, either run:

git commit --verbose

…or configure it accordingly:

        verbose = true

Show (long enough) hash

git rev-parse --short <long hash>


It's handy to tracking multiple branches simultaneously with git-worktree(1)

cd freebsd-ports; git worktree add -b 2021Q3 ../freebsd-ports-2021Q3 freebsd/2021Q3
cd freebsd-src; git worktree add -b stable/13 ../freebsd-src-13 freebsd/stable/13

Helper Scripts


year=$(date +"%Y")
month=$(date +"%m")


git worktree add -b ${branch} ../freebsd-ports-${branch} freebsd/${branch}

GitTips (last edited 2023-03-13T14:24:45+0000 by LiWenHsu)