Solved installing and updating the src tree with git?

BostonBSD

Active Member

Reaction score: 53
Messages: 119

Installing and updating the src tree with svn went like this [for release 12.2] into the src directory:

svn checkout https://svn.freebsd.org/base/releng/12.2 /usr/src

For Freebsd-Current [currently version 13] it is:

svn checkout https://svn.freebsd.org/base/head /usr/src

Updating the src tree went like this:

svn update /usr/src

===========

With GIT

To obtain the code for FreeBSD Current [in /usr/src/ssh:/anongit@git.freebsd.org/src.git/] {i suppose this directory name could be anything, so long as it ends with '.git'? edit: it can be anything}:
Code:
cd to /usr/src/
git clone https://git.freebsd.org/src.git ssh://anongit@git.freebsd.org/src.git

To update the src tree, cd to the "/usr/src/ssh:/anongit@git.freebsd.org/src.git/" directory and run

git pull

It should give a warning and some options, choose one of the options and the warnings will go away.

The question I have is how do I clone a FreeBSD-Release, say for FreeBSD 12.2? I tried:

git clone https://git.freebsd.org/src/releng/12.2.git ssh://anongit@git.freebsd.org/src/releng/12.2.git

But this isn't correct.

Edit {thanks goes to the nice people who posted below}:
================
------------------

To obtain the code for FreeBSD Current [in /usr/src]:

Code:
git clone https://git.freebsd.org/src.git /usr/src

To obtain the code for FreeBSD Release 12.2 [in /usr/src]:

Code:
git clone -b releng/12.2 --depth 1 https://git.freebsd.org/src.git /usr/src

To obtain the code for FreeBSD 12 Stable {current of release 12} [in /usr/src]:

Code:
git clone -b stable/12 --depth 1 https://git.freebsd.org/src.git /usr/src


-----

To Update the code:

You need to configure git before using "pull."

For the lastest updates to the src tree:

Code:
git config pull.ff only

change directory to /usr/src and type:

Code:
git pull


[I tried to compile a kernel using the default merge configuration and "uname -a" told me my kernel was dirty after the install. I did another compile using the ff config and everything went like normal.]
 
Last edited:

scottro

Daemon

Reaction score: 761
Messages: 1,872

For 12.2 you can use
git clone -b releng/12.2 --depth 1 https://git.freebsd.org/src.git src

Assuming you were in /usr and wanted the source code in /usr/src
That should bring you the latest release version of 12.x, currently 12.2

For 12.1

git clone -b releng/12.1 --depth 1 https://git.freebsd.org/src.git src


Earlier, I'd had that as git clone -b stable/12 --depth 1 https://git.freebsd.org/src.git src

This was due my misunderstanding the Losh page. The -b is for branch so if you put -b stable you'll get the STABLE branch, the latest one of 12.x that is available. (If you do -b stable/12). Also fixed it on my page.

There are a couple of posts here, getting harder to find as time goes on, one which gives links to pages with quick tutorials, and another very long thread which got into the politics of git vs. svn, but has the commands buried somewhere in the thread. I was fortunate enough to find it, (and also ask about getting other release versions than the latest and get quick answers from kind people on the forum.)
 
Last edited:

scottro

Daemon

Reaction score: 761
Messages: 1,872

As I've gotten some thanks for my post, I should point out that the thanks is due to users vigole, SirDice, Jose, jb_fvwm2, and the Warner Losh tutorial at http://bsdimp.blogspot.com/2020/10/freebsd-git-primer-for-users.html
I've now put up my own little page about it, (where I also thank everyone), so that I don't have to go through searching forums and my disorganized notes each time the question gets asked. I suspect that it will be asked quite a bit in the near future, before everyone gets used to it
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 10,921
Messages: 36,835

We should probably put up a quick howto with the most basic commands to get things started. I've been 'migrating' my source trees to git over the weekend. And by 'migrating' I really mean rm -rf /usr/src/* and a fresh git clone :D

But I already have some experience with git (nothing major besides some push/pull and merges), so it wasn't much of a problem for me. For most people net/gitup should probably suffice.
 

bagas

Active Member

Reaction score: 5
Messages: 216

Is there an official instruction for updating the system?
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 10,921
Messages: 36,835

Yes, but doesn't cover how you get the source, only how to build it.
 

scottro

Daemon

Reaction score: 761
Messages: 1,872

Here's my page. I don't consider it a howto, but the commands work for me. (Though in honestly, I have't used svn up in awhile, mostly I use freebsd-update. The only CURRENT I use is on laptop that won't work with release and I often don't even update it, just rebuild with KERNCONF=GENERIC-NODEBUG.

https://srobb.net/fbsdgit.html

(no ads, a bit of javascript to say when it was last updated, but you can block javascript and still see the page--save of course, for the last time it was updated.).
 

bagas

Active Member

Reaction score: 5
Messages: 216

Here's my page. I don't consider it a howto, but the commands work for me. (Though in honestly, I have't used svn up in awhile, mostly I use freebsd-update. The only CURRENT I use is on laptop that won't work with release and I often don't even update it, just rebuild with KERNCONF=GENERIC-NODEBUG.
Do I need to delete the current sources /usr/src/ before updating the kernel sources via git?
 

bagas

Active Member

Reaction score: 5
Messages: 216

uname -rms
FreeBSD 11.4-RELEASE-p6 amd64
Doing.
rm -rf /usr/src
cd /usr/
git clone -b releng/11.4 --depth 1 https://git.freebsd.org/src.git src
git pull
Further according to the old scheme.
make -j8 buildworld
make -j8 buildkernel KERNCONF=sdff
make installkernel KERNCONF=sdff
make installworld
...
...
For subsequent updates.
git pull
Right?
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 10,921
Messages: 36,835

The git pull has to be done in the /usr/src/ directory, but yes, that's all.

Git might complain about "pull" the first time you use it though.
Code:
root@hosaka:/usr/src # git pull
hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint:
hint:   git config pull.rebase false  # merge (the default strategy)
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
Setting git config pull.ff only should be fine.

Instead of using a full git client you might want to give net/gitup a try too. It's specifically created for people that only want to grab the latest source code and keep that updated.
 
OP
B

BostonBSD

Active Member

Reaction score: 53
Messages: 119

If you want to compile a kernel just to try it out you can put this code in a config file and follow the directions [it customizes the color scheme of the VT(4) console driver, you can change it to whatever you want, make sure the code you have is the same release as the system]:


Code:
#Color names can be found in the "/usr/src/sys/sys/terminal.h" file.

include GENERIC
ident BSDKERNEL

options    TERMINAL_NORM_ATTR=(FG_WHITE|BG_BLUE)
options    TERMINAL_KERN_ATTR=(FG_YELLOW|BG_BLUE)


Make sure to change the ident directive to whatever the filename is, in this case it is "BSDKERNEL". It goes in the "/usr/src/sys/amd64/conf" directory, for amd64 processors.

https://www.freebsd.org/doc/handbook/kernelconfig-config.html
 

bagas

Active Member

Reaction score: 5
Messages: 216

The git pull has to be done in the /usr/src/ directory, but yes, that's all.

Git might complain about "pull" the first time you use it though.
Is everything correct for the rest of the system update actions?
I rarely use git.
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 10,921
Messages: 36,835

Is everything correct for the rest of the system update actions?
I rarely use git.
Nothing else needs to be configured. Other settings can be set but those are really only important if you need to commit/push changes.
 

bagas

Active Member

Reaction score: 5
Messages: 216

Nothing else needs to be configured. Other settings can be set but those are really only important if you need to commit/push changes.
I don’t fully understand.
At the moment the system FreeBSD 11.4-RELEASE-p6 amd64
Used svn. (svn switch svn://svn.freebsd.org/base/releng/11.4 /usr/src; svn update /usr/src/)
How to install updates correctly now?
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 10,921
Messages: 36,835

git clone -b releng/11.4 --depth 1 https://git.freebsd.org/src.git /usr/src
This creates a fresh checkout (similar to svn checkout ...) and fetches only the releng/11.4 branch. That's the correct branch for 11.4-RELEASE.
To update it (i.e. fetch the security updates), you only need to run cd /usr/src && git pull.
 

bagas

Active Member

Reaction score: 5
Messages: 216

git clone -b releng/11.4 --depth 1 https://git.freebsd.org/src.git /usr/src
This creates a fresh checkout (similar to svn checkout ...) and fetches only the releng/11.4 branch. That's the correct branch for 11.4-RELEASE.
To update it (i.e. fetch the security updates), you only need to run cd /usr/src && git pull.
Do you need to delete the current sources (/usr/src/) before (git clone -b releng / 11.4 --depth 1 https://git.freebsd.org/src.git /usr/src)?
 
OP
B

BostonBSD

Active Member

Reaction score: 53
Messages: 119

Do you need to delete the current sources (/usr/src/) before (git clone -b releng / 11.4 --depth 1 https://git.freebsd.org/src.git /usr/src)?
Yes, unless you have any changes you would like to keep [make sure everything is deleted by using "ls -a"].

You could also just rename your src directory src2, and create another src directory.
If it doesn't work delete the new directory and change the other one back.
 

recluce

Active Member

Reaction score: 39
Messages: 164

Thank you all for the instructions, this worked right off the bat.

I wonder if the move from svn to git has any advantages from a user perspective. So far, the only difference I could see is that installing git required a boat load of dependencies to be installed.
 

ShelLuser

Son of Beastie

Reaction score: 2,054
Messages: 3,770

I wonder if the move from svn to git has any advantages from a user perspective.
Dozens. I just converted my src and doc repositories yesterday evening and I'm honestly a little excited.

But let's share some obvious ones...

Branches

Once you cloned the source tree ( git clone https://git.freebsd.org/src.git /usr/src) you may want to use # git checkout releng/12.2 (from inside /usr/src), this will set your branch to the current version. The advantage you wonder?

Let's say for the sake of argument that 12.3 will be out next month. Normally you'd have to set up a new source tree and then make the switch, but with Git you no longer have to. Better yet: because you forcefully set your branch to 12.2 you can easily plan the switch yourself. So the moment you're ready to make the transition just check out releng/12.3 (see command above) and perform the upgrade as usual. Ergo: one source tree to "rule them all".

It gets better... let's say that you ran into major bugs which require that you move back to 12.1 out of all setups in order to fix things. Now what? Simple: just check out the branch! If you want a good example of what I'm talking about: git branch -r (from /usr/src of course), you'll see! It's not just one source tree, it's one with multiple branches thus one which supports multiple versions as well.

Important disclaimer: There's more to this strategy, because different branches can even have different upstreams. If you check out the main source tree then Git will know how to update main but it won't know anything about releng/12.2. So... to keep this up to date you'd use: git pull origin main. When in doubt stick to main.

Cloning

Are you administrating multiple servers? And do you happen to build all of them from source? SO how do you set up the source tree on your other servers? I suppose to save bandwidth you could try to copy /usr/src yourself but it would get tedious really quick. It was easier (IMO) to just re-use svn co https://svn,freebsd.org ...., and so on.

With Git you maintain your own official source tree, with all the perks that come attached to that. Including the option to clone your local repository! So, from the 'other' server: # git clone ssh://shell@10.0.0.5/usr/src /usr/src (obviously you'd need to use your own credentials).

While this saves you bandwidth it also creates a possible problem: now your "other server" isn't tracking the official source repository but your servers repository. This can be a good thing (all updates will now get retrieved using your LAN) but it can also cause issues. For example: what if your main server goes down and you need to update the "other" server?

Fortunately this is easily fixed: # git fetch --set-upstream https://git.freebsd.org/src.git (from /usr/src of course). So: you grabbed your source tree from a local server, then changed the upstream to the official repository so that your "other server" will now also track the official resources.

No downloading when you don't want to

Want to check if your source tree is still up to date but you don't want to risk having to download a whole bunch just yet? Easy! # git fetch. After that a mere git status will tell you exactly if your source tree is up to date or not.... then you can always use # git pull when it best suits you.

Of course if you just want easy just use pull and be done with it.

Always keep track of things...

When 12.3 hits this will manifest itself with a new branch and eventually main will be switched as well, I already mentioned how to control this. But... how to tell for yourself?

git log:
Code:
% git log
commit cef1942711624c6cf1d237118531cfad9ade05ac (HEAD -> main, origin/main, origin/HEAD, releng/12.2)
Author: Alex Richardson <arichardson@FreeBSD.org>
Date:   Wed Jan 20 09:56:01 2021 +0000
Notice the mention of origin/main and releng/12.2? That tells me that those two branches are one and the same. At some time that may say releng/12.3 though and then I'll know that I may want to check out a specific branch if I'm not ready to upgrade just yet.

Maintain your own changes!

Are you a kernel hacker wannabe (no disrespect here mind you!)? Then you'll love this.. Just set up your own branch and start hacking, you don't have to worry about a thing because you can always check out the main branch and perform any required updates.

Oh, it gets better.. you can even apply the official changes to your own test environment (so: your own dev branch so to speak) without affecting any of your changes. When a file you've been working on also got an update then Git will tell you and allow you to merge the changes as needed.

So... you can hack the kernel and still keep things up to date!

....

There you go, a few things from the top of my head. I'm probably going to check if I can turn this into a guide of some sort, might be useful for some. Sorry for the long read, but I'm honestly a little excited about this change, Git has become one of my favorite tools quite some time ago so yah... I enjoy seeing it being put to work for real.
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 10,921
Messages: 36,835

devel/git (the "full" version) has these options:
Code:
    ===> The following configuration options are available for git-2.30.0:
         CONTRIB=on: Install contributed scripts
         CURL=on: Install curl support (provides HTTPS transport)
         CVS=on: Enable CVS support
         GITWEB=on: Install gitweb
         GUI=off: GUI (Graphical User Interface) support
         HTMLDOCS=off: Install additional documentation
         ICONV=on: Encoding conversion support via iconv
         NLS=on: Native Language Support
         P4=on: Enable Perforce support
         PERL=on: Perl scripting language support
         SEND_EMAIL=on: Enable the git-send-email(1) script
         SUBTREE=on: Install git-subtree
         SVN=on: Subversion support
    ====> Options available for the radio PCRE_VERSION: you can only select none or one of them
         PCRE=on: Use Perl Compatible Regular Expressions
         PCRE2=off: Use Perl Compatible Regular Expressions (v2)
    ===> Use 'make config' to modify these settings

Code:
This version provides the bare minimum git experience without any bindings.

Code:
This version provides the tiniest usable git experience, depending only upon
ftp/curl for http(s) support.
 
Top