Using git To Get FreeBSD Source Code

Recently, FreeBSD has switched from svn to git as the method to get source code. Those unfamiliar with git, including myself, have been unsure of the syntax. Thanks to Warner Losh's git primer, and help from FreeBSD forums users, Jose, jb_fvwm2, vigole, SirDice, and probably some others whom I've overlooked, and, I hope, will accept my thanks and apologies, I've figured out syntax that works. At time of writing, January, 2021, the present release is 12.2-RELEASE. To get the present release--though it's 12.2 now, by the time the reader sees this, it may be 12.3 or something else--the following works.
git clone -b releng/12.2 --depth 1 https://git.freebsd.org/src.git /usr/src

If you were following 12 stable, right now, (January, 2021) the following would get you 12.2-STABLE. When 12.3 is available, you would get that. In other words, it will bring you the latest available version of 12.x-STABLE
git clone -b stable/12 --depth 1 https://git.freebsd.org/src.git  /usr/src

To get an earlier release of the 12.x branch, say, 12.1, you can use
git clone -b releng/12.1 --depth 1 https://git.freebsd.org/src.git /usr/src

To get CURRENT one uses
git clone https://git.freebsd.org/src.git /usr/src

To update source that you've pulled (like doing svn up)
cd /usr/src
git pull

FreeBSD-13.x is now the latest version. To get that
git clone -b releng/13.0 https://git.freebsd.org/src.git /usr/src

Again, this information was given me by others. I'm just putting up this page to have a convenient place to point people when the question is asked on forums, as well as making it easier for me to find.

Ports has also been converted to git. Actually, for ports, I've just used gitup, described below.

There is also git-tiny. For those who don't need all of git, but just want to clone source or ports, it is a smaller substitute. Another substitute is gitup. This can also replace git for those who don't need anything more than to clone ports or source. It has a /usr/local/etc/gitup.conf file which you may want to edit. For example, in mid March of 2021, its default for release version is 11.4. As I'm using 13.0 on my workstation, I would change that to 13.0. Were I still using 12.2, I'd just change it to 12.2. Its syntax is slightly different. Once you've set your version in its conf file, you run, to say, get the source for 13.0
gitup release 

The repository and destination of /usr/src are already configured in /usr/local/etc/gitup.conf. One can also choose stable or current (as the argument to get STABLE or CURRENT). The other configured sections, as of March 2021 are ports and quarterly (which is, as you see if you look at the conf file, for the quarterly version of ports.

As of April, 2021, one can now use git with ports as well. You can still use portsnap, but gitup works very well. Note that this is as of April, 2021.

The /usr/local/etc/gitup.conf has to be edited. For ports, the default may be github.com, that should be changed to /ports.git. The branch should be changed from master to main. These changes may have taken place by the time you see this article.

Using gitup doesn't create an INDEX file. Depending upon your usage, this may not even matter to you. On occasion, I use the handy pkg psearch, to search for a port. Using psearch requires an INDEX file. I am able to run, in /usr/ports, with root privilege, make fetchindex. Note that there some issues with INDEX right now, see this thread on FreeBSD forums. But, for my needs, just using it for psearch, the INDEX file pulled with make fetchindex works for me.