On Mon, Nov 29, 2021 at 05:44:51PM +0100, Uwe Brauer wrote:

[...]

> Ok, right, I see now that I left out that important part of information. 
> It should have been
> 
>     1. I created the copyright (and copy branch one of them was silly anyway) 
> and
> 
>     2. Added two commits into that branch(es), if I remember correctly one
>        commit belonged to two branches (that is possible right?)

Well, yes and no - depends on how one looks.
In Git, a commit does not in any way records explicitly which branch it was
created "on" (and it's possible to record a commit which does not belong to
any branch even initially), and hence the fact of belonging to a branch is a
dynamic properly which, in Git, is defined through the concept of
reachability. A branch is merely a pointer to some commit with the added logic
that when this branch is checked out, and a new commit recorded, it will
update the checked out branch such that it now points to that new commit.
So, if we take a branch, we can inspect the commit it points at, find its
parent commit(s) then the parent commits of those commits and move all the way
down - until we eventually hit one or more "root" commits - those with no
parents. (In Git, graphs of commits are obviously acyclic, so we'll always
guaranteed to arrive at one or more root commits.)

One way to achieve the situation you have got in with plain Git is:

  git checkout master

  git add ...
  git commit ...

  ^ repeat twice to create two unneeded commits

  git branch copy
  git branch copyright

  ^ the branches master, copy and copyright all point at the same commit now.

  git push --all origin

  ^ pushes all existing local branches to the same-named branches in the
    remote repo.

[...]
> > That's because the command means "delete the local branches „copy” and
> > „copyright”". From your original post, it wasn't clear you do not have such
> > local branches.
> 
> That is were I was  (and still am) confused: I created these branches locally 
> and
> then pushed, I thought they would then be in both places: in my local
> repository and in the remote server repository.

Now that makes me confused, too, because a sequence of commands I showed above
would make you end up with the three local branches, and the following "push
all" command would create remote branches origin/copy and origin/copyright
(and update origin/master).

Sure, there was a way to create only remote branches w/o creating local -
say, by pushing like

  git push origin HEAD:master HEAD:refs/heads/copy HEAD:refs/heads/copyright

but I doubt you'd do that in your right mind :-)

I think it's simpler to assume you have somehow managed to delete those two
extraneous local branches but forgot about that. Not sure we can find out
unless you have a history of the shell commands run (and that was a CLI tool -
which were used for deletion).

[...]

> Ok thanks for telling me. I will in the future double cautious and first
> push to a sandbox somewhere before pushing to a shared repository.

I would just recommend to unlearn "--all".
Basically, the course of action is as follows:

 1. Inspect the branch you're about to push looks OK (`git log -p`, `gitk` or
    whatever else).

 2. Push exactly that branch - with

      git push origin HEAD

    supposedly being the most convenient shortcut for "update the branch I'm 
    on with the commit it points at".

-- 
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/20211129175408.fq2mldvvvin3ihy3%40carbon.

Reply via email to