git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Why does 'git branch -d' act differntly after clone?

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 20, 2015, 15:49 UTC
Message-ID
<xmqqa8tm7yez.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CALwJaCzYgDKdcT7H7=5x0fnNRv4MsrtjJoHJcB9rJyh3dU--xQ@mail.gmail.com>
Konstantin Hollerith <khollerith@gmail.com> writes:
> Why does git branch -d acts differently after a clone?

In the former case, that branch is the only thing that knows about the commits near the tip of it. Immediately after you clone that repository, you have a copy of that branch as a remote-tracking branch for origin/neuerTestBranch. You didn't say how you got a local copy of it in there, but I'd imagine that in the clone you did something like:

    $ git checkout neuerTestBranch
which is a short-hand for
    $ git checkout -b neuerTestBranch origin/neuerTestBranch

and then went back to a branch other than that branch when you asked the branch to be removed, e.g.

    $ git checkout master
    $ git branch -d neuerTestBranch
without building any further history on neuerTestBranch.

Now, your local neuerTestBranch is a mere unmodified copy of the remote-tracking branch origin/neuerTestBranch; the commits on the former will not become unreachable if you remove neuerTestBranch, because they are all reachable via origin/neuerTestBranch. And that is why the deletion of it has less severe potential of information lossage, compared to the original case where you attempt to remove the only copy.

Previous: Konstantin Hollerith
Message 2 of 2 in “Why does 'git branch -d' act differntly after clone?”
  1. Konstantin HollerithAug 20, 2015
  2. Junio C HamanoAug 20, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.