> On Sat, Apr 15, 2023 at 2:35 AM Uwe Brauer <o...@mat.ucm.es> wrote:

> Not all references are branches, but all the ones that are branches
> are fetched, except in a different namespace: /refs/remotes.

> Local branches are /refs/heads, and that's what `git branch` shows.
> Remote branches are in /refs/remotes, and that's what `git branch
> --remotes` shows.

> But the remote branches are not always up-to-date, that's why they are
> called "remote tracking branches", that is: they track remote
> branches, but they aren't always necessarily the same.

> This is OK, but you can create a branch and check it out at the same time 
> with:

>     git checkout -b feature origin/feature

> Except, for new users `git switch` may be easier:

>     git switch -c feature origin/feature

> A more recommended way is to "track" the original branch:

>     git switch -c feature -t origin/feature

> To understand what this does you would need to learn about the concept
> of "upstream tracking branch" [1], but you don't have to, just know
> that it's generally better if you set it up.

> You don't have to type that, because `git switch` can guess what you
> want to do, so just:

>     git switch --guess feature

Ok thanks that is useful, I will put in my HOWTO.org file, for the moment, 
otherwise to much information in a very short time.

> `git checkout` is more appropriate here.

> There are remote tracking branches, but they are not in the
> /refs/remotes namespace, they are in the /refs/heads namespace, so
> your local branches are remote tracking branches.

> If you do changes on a "feature" branch, they will be overridden when
> you do `git fetch`.


> Once a mirror, always a mirror.

> Yes, but I think you should forget about using a mirror, that's not
> what you want.

> I think what you want is to mirror all the remote branches only once,
> and otherwise have a normal repository (not a mirror).

> You can do that with this command:

>     git fetch origin refs/heads/*:refs/heads/*


> This will create local branches for all the remote branches (the
> remote refs/heads/foo will become a local refs/heads/foo). The problem
> with this approach is that the local branches will not track the
> remote branches.

> At the end of the day I think what you should do is do `git switch`
> for every remote branch, which git can help:

>     git for-each-ref --format='git switch %(refname:lstrip=3)'
> refs/remotes/origin

Definitely going in my HOWTO.org file

Warning: Content may be disturbing to some audiences
I strongly condemn Putin's war of aggression against the Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the ban of Russia from SWIFT.
I support the EU membership of the Ukraine. 

You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to