I've followed the way documented here (chapter 5.2.2) when I've switched from subversion to git (chase the decision of FreeBSD project) to clone src and ports.
This was because the description in the Handbook was NOT yet ready at the moment. (To be honest, what I've followed was the draft of the linked document, as official one was not yet ready, too.)
A difference is that I've already used Root on ZFS, but not created by the installer (bsdinstall), and as git wanted blank /usr/src and /usr/ports respectively, I've done the undocumented way like below.
- To be paranoid, created /usr/src-snv and /usr/ports-svn as temporary mount point.
- Unmounted /usr/src and /usr/ports with
zfs umount.
- Change mountpoint of prior src and ports datasets to the temporary ones.
- Created new dataset src-git and ports-git under the parent datasets of each, with mountpoints /usr/src and /usr/ports respectively.
- Cloned src and ports repo as described in above-linked git primer.
- Once confirmed the new /usr/src and /usr/ports OK, destroyed former src and ports datasets and removed the temporary mount point.
Note that I'm not a committer, so followed clone part and confirmation part (the first 2 parts) only.
After the clones are finished, both repos are pointing at the head (top) of main branch in each repo. For me, ports repo is OK as-is. So as my test environments for main (aka -CURRENT) in another physical drive.
But for my daily driver (latest stable branch), it's not appropreate.
So checked out the wanted branch. This can be appricable when switching to different branch. As I cannot recall at which branch it actually was, example below is to checkout releng/15.1, which is used for 15.1-RELEASE.
cd /usr/src && git checkout releng/15.1