Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How does git know when a branch's upstream is gone?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading