git setup/usage question

Ulrich Spörlein uqs at freebsd.org
Wed Jan 27 20:55:48 UTC 2021


On Tue, 2021-01-26 at 15:10:17 +0100, Milan Obuch wrote:
>Hi,
>
>I am working on new workflow setup after svn->git move. I did some
>tests, starting with Warner's Hacking Blog at
>http://bsdimp.blogspot.com/2020/10/freebsd-git-primer-for-users.html
>and trying some suggestion and ideas taken from both this and current
>mailing lists.
>
>After gaining some bits of knowledge I am going to create something
>more elaborate... for me.
>
>What I would like to achieve:
>
>- use one repository for all branches of interest and as working area
>  too
>
>- use separate working directory for each branch and working area
>  (possibly multiple for multiple projects)
>
>- track remote repository periodically and update working tree as
>  needed (immediatelly after repository update or delayed when other
>  work on a tree is being done at the moment).
>
>I do not see in this anything special, just the primer mentioned above
>handles basically just single working area case, which makes necessary
>some switching (via checkout of different branch or somesuch).
>
>So what I did:
>
># git clone --config remote.freebsd.fetch='+refs/notes/*:refs/notes/*' --bare https://git.freebsd.org/src.git /mnt/src/.git
># git -C /mnt/src/.git worktree add /mnt/src/main main
># git -C /mnt/src/.git worktree add /mnt/src/13 stable/13
># git -C /mnt/src/.git worktree add /mnt/src/12 stable/12
># git -C /mnt/src/.git worktree add /mnt/src/11 stable/11
>
>This way I have nice directory structure in /mnt/src, I can use
>individual trees for either local null mount (for jails and similar
>usage) or remote mount via nfs.
>
>Look for status:
>
># git -C /mnt/src/.git worktree list
>/mnt/src       (bare)
>/mnt/src/11    09bdde595dd [stable/11]
>/mnt/src/12    70cdab054c8 [stable/12]
>/mnt/src/13    da2dfec8f75 [stable/13]
>/mnt/src/main  25cdacf79b0 [main]
>
>Nice! Clear, easy to understand. With some scripting, this could be
>used to create id string for uname use (there is a thread about this on
>arch list, this is something I need to think about especially for
>remote building with sources mounted over nfs).
>
>Now for updating, trying to fetch...
>
># git -C /mnt/src/.git fetch
>From https://git.freebsd.org/src
> * branch                    HEAD       -> FETCH_HEAD
>
>This looks like there is nothing new to fetch at the moment. So waiting
>a bit for new commit... waiting a bit more... trying again...
>
># git -C /mnt/src/.git fetch
>remote: Enumerating objects: 5, done.
>remote: Counting objects: 100% (5/5), done.
>remote: Compressing objects: 100% (5/5), done.
>remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
>Unpacking objects: 100% (5/5), 42.60 KiB | 484.00 KiB/s, done.
>From https://git.freebsd.org/src
> * branch                    HEAD       -> FETCH_HEAD
>
>This time there is something new... I need a merge now.
>
># git -C /mnt/src/.git merge
>fatal: this operation must be run in a work tree

No, you don't want to merge. Why would you merge? You want to run `git 
pull`, that will pull the updates from the remote refs into your local 
refs.

>
>I am a bit stuck now. What does it mean 'being in a work tree'? Doing
>'cd /mnt/src/main' or similar before git command does not change
>anything. I read 'man git-merge' but still no clue. It must be
>something simple, I just do not see it.
>
>Also,
>
># git -C /mnt/src/.git log
>
>does not show new commit yet. If I do 'git pull --ff-only' command
>(with another git repository, created exactly the way mentioned in
>primer) at the same time, I see new commit in log output. It looks like
>log is updated on merge, not fetch, judging from my previous litlle bit
>of experience with git, so this maybe should be expected, I just do not
>know.

No, the log isn't updated on `merge` (probably just sloppy wording), 
what your log does is show the log of the local ref and you haven't 
pulled anything into it yet. If you had done git log 
refs/remotes/freebsd/main (or whatever that is on a bare repo), then 
you'd have seen the updates.

>So the big question - did I the right steps to achieve what I want,
>descibed in the beginning of this mail? Is this way OK to use, or
>should I use some other way to achieve this?

Yep, all looks perfectly fine, except you need to run git pull to bring 
in remote changes. So usually `git fetch` to update your copy of the 
remote refs, then `git pull --rebase` to bring in the changes into your 
local copy of the ref _and_ update the checked out copy.

You might have to tweak all that a bit though for the bare repo case 
with worktrees.

hth
Uli


More information about the freebsd-git mailing list