git setup/usage question

Mark Millard marklmi at yahoo.com
Wed Jan 27 23:29:48 UTC 2021



On 2021-Jan-27, at 12:55, Ulrich Spörlein <uqs at freebsd.org> wrote:

> On Tue, 2021-01-26 at 15:10:17 +0100, Milan Obuch wrote:
>> . . .
>> # 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.

QUOTE from https://git-scm.com/docs/git-pull :
git pull is shorthand for git fetch followed by git merge FETCH_HEAD
END QUOTE (other wording for the likes of --rebase not quoted)

Looks to me like he tried to do something like what
git pull does, but in two explicit, separate steps:
git fetch and git merge .

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

He did both the git fetch and a git merge (but not a fast forward
merge). But he had cloned with --bare and:

QUOTE from https://git-scm.com/docs/git-clone :
--bare
. . . Also the branch heads at the remote are copied directly to
corresponding  local branch heads, without mapping them to
refs/remotes/origin/ . When this option is used, neither
remote-tracking branches nor the related configuration variables
are created.
END QUOTE

So things seem to be odd compared to the normal expected
type of configuration for FreeBSD.

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

It looks to me like he is using a configuration (--bare)
outside the range FreeBSD is intending to deal with and
so he needs his own fairly-unique procedures for using
git for FreeBSD activity.

===
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)



More information about the freebsd-git mailing list