Solved installing and updating the src tree with git?

BostonBSD

Member

Reaction score: 3
Messages: 25

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: 624
Messages: 1,660

For 12.2 you can use
git clone -b stable/12 --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


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.)
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 9,783
Messages: 34,911

To update the tree you just cloned,
Code:
cd /usr/src
git pull
 

scottro

Daemon

Reaction score: 624
Messages: 1,660

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: 9,783
Messages: 34,911

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: 3
Messages: 159

Is there an official instruction for updating the system?
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 9,783
Messages: 34,911

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

scottro

Daemon

Reaction score: 624
Messages: 1,660

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: 3
Messages: 159

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: 3
Messages: 159

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: 9,783
Messages: 34,911

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

Member

Reaction score: 3
Messages: 25

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: 3
Messages: 159

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: 9,783
Messages: 34,911

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: 3
Messages: 159

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: 9,783
Messages: 34,911

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: 3
Messages: 159

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

Member

Reaction score: 3
Messages: 25

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.
 
Top