4

Say I have a branch on git, my-branch. I push it to a remote, then delete it from said remote, and leave my local copy remaining.

git checkout -b my-branch
git push origin my-branch 
git push origin --delete my-branch

Git then seemingly knows nothing of an "origin/my-branch", but gives indications that it knows that there was once an origin/my-branch, such as in .git/COMMIT_EDITMSG:

# Your branch is based on 'origin/my-branch', but the upstream is gone.

My question is, how is git deducing that there once was an origin/my-branch that is now gone? Where is this information stored/computed from?

1
  • 1
    Have a look in the .git folder. There's a whole history there in various forms.
    – isherwood
    Commented Jun 26 at 14:32

1 Answer 1

6

The mapping between your local branch and the remote branch is stored in .git/config like

[branch "my-branch"]
    remote = origin
    merge = refs/heads/my-branch

There is directory which tracks local branches

.git/refs/heads/{branch-name}

Lastly there is directory that tracks branches per remote

.git/refs/remotes/origin/{branch-name}

Therefore if you have a branch present in config but that branch is missing from the corresponding remote, then Git knows it has been deleted upstream but used to have a mapping.

1
  • 1
    Depending on how deep one wants to go, we can find the exact logic in the git source code: github.com/git/git/blob/… Indeed the file remote.c has several mentions of the path remotes/ Commented Jun 26 at 15:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.