>>> "KK" == Konstantin Khomoutov <kos...@bswap.ru> writes:

> On Mon, Nov 14, 2022 at 05:57:27PM +0100, Uwe Brauer wrote:
>> I am sorry for such an elementary question, but using mainly hg, I found
>> the following very confusing.

> No, the question is not elementary, and yes, the behavior is confusing.

First of all thanks very much for this very detailed answer, and the solution 
to my problem. 

,----
| git checkout feature
| git push origin feature
`----

However I still have a lack of understanding of some concepts.

Since I am basically a hg user, bare with me.

I thought the main difference between git and hg, is (besides the
command syntax) the way branches are considered, a git branch is similar
to a bookmark, while a named branch has no equivalent in git.

However I now see that also the concept of remote branch tracking sets
git apart from mercurial.

And I have to say that the confusion I have may be caused partially by
the naming convenience.

    1. That concerns the name origin for the remote which is confusing.
       If I clone a repository that might be justified, but if I
       generate a repository that I later push for the first time,
       origin is well confusing (fortunately that
       can be changed by git remote rename origin github)

    2. That concerns the prefix dropping  for local branches:
       Is there a way to configure git that it does not drop the prefix
       for local branches?

You mentioned 

git for-each-ref --format='%(refname)'

Well I presume I could use an alias but is there any setting that would
allow me to see

 git branch -a 

Something like this 
local/main


Anyway now to my biggest problem. 
I am not entirely sure I understand your explanations about local and
remote branches. 

If I clone a repository, why doesn't git,
copy/clone  *all* branches? That is the way cloning works for mercurial,
and I find that perfectly logic and convenient.



You said 
>  - "Remote" branches are sort of "bookmark" to the state of the branches
>    in some named remote repository Git has contacted with - specifically,
>    the last time it did so.

For example 

 git branch -a 



* main
  remotes/origin/HEAD -> origin/main
  remotes/origin/feature
  remotes/origin/main

So there is no local copy of the feature branch on my local cloned repository!?

In mercurial after I clone, I can checkout the branch I want work on it and 
then push
(well there might be conflicts because somebody else pushed, but that is
a general problem/feature of DVCS.)

Then you write 

>   git checkout feature

> Git would notice there is no local branch named "feature" but there exist a
> remote branch named "feature", and would create a local branch "feature"
> pointing at the same commit the remote one points at, and tracking that remote
> branch.


Does this mean that when I do that, then git downloads all commits of
that branch? Because I would need them to make my changes?

It seems that you say 

git checkout feature 

Is a shortcut for the following commands

> Alternatively, you could do that explicitly without involving any magic
> of the short-circuit command invocation:

>   git branch feature origin/feature # create local branch off a remote one
>   git checkout feature              # check local branch out
>   git branch -u origin/feature      # make current branch track origin/feature

Does any of these command downloads the commits of the remote branch feature?

I think this crucial part I need to understand.

Then you say:
> When you check a remote branch, Git makes the HEAD ref point directly at the
> commit which that branch points at - a situation known as "detached HEAD".
> Recording new commits will update just the HEAD, and not any branch.
> This is a pretty normal situation for seasoned Git uses (I, for one, mostly
> work in this state) but it's not recommended for inexperienced users: I have
> described what happens to have you prepared for the case which would occur
> if you were to run

>   git checkout origin/feature

> as you would end in that detached HEAD state.

I am not sure I understand this, what is the workflow? What is the
benefit of this approach?

So I think my question boils down, when and how do I obtain a local copy
of a remote branch in order to do some changes and push them.

Regards

-- 
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 
https://groups.google.com/d/msgid/git-users/87h6yz3o5v.fsf%40mat.ucm.es.

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

Reply via email to