grybouilli
grybouilli

Reputation: 410

How did I erase a branch from github history?

I actually didn't know how to ask this properly, I hope my question fits.

Here's what happened: I was basically working on a small project with git and so I created a new branch locally that I then pushed to my remote. Everything fine so far.

Today, as I was done with my branch, I merged it to master and then locally deleted it (git branch -d branch_to_delete) and then used git push to see the changes appear on github. Thing is, on github, the branch still existed and when I looked at the network, it looked like it never existed.

enter image description here

Weird right? So then I used git push origin -d to_delete_branch and the branch seemed to have been deleted on github but still it won't appear on the network... So my question is, what did I do wrong? x) Or actually, is anything wrong? Maybe it is supposed to look that way...

Upvotes: 3

Views: 61

Answers (2)

Schwern
Schwern

Reputation: 164769

This is probably because rather than merging Git did a "fast-forward".

Let's say you had this.

A - B [master]
     \
      C - D [feature]

Git branches are just labels pointing at a commit. Commits A and B are on master. And feature built C and D on top.

When you git merge feature Git notices that instead of merging it can simply move master to D. No merge necessary.

A - B
     \
      C - D [feature]
            [master]

The kink at B - C is artificial, so you see a linear history.

A - B - C - D [feature]
              [master]

This is a "fast forward". Git would have mentioned this when you did the git merge.

In contrast, let's say you did some work on master before merging.

A - B - E [master]
     \
      C - D [feature]

Because master and feature have "diverged" Git needs to merge the two code bases. git merge feature will produce a merge commit and the branch is retained in history.

A - B - E - F [master]
     \     /
      C - D [feature]

For this reason, use git merge --no-ff meaning "no fast-forward" to guarantee there is always a "feature bubble" even after the branch (really just the branch label) is deleted. Then just by looking at the history one knows that C and D were done as a logical group, and the merge commit message on F can provide context for why they were done.

Upvotes: 2

matt
matt

Reputation: 535086

A branch is just a name. That name exists, pointing to some commit or other, or it doesn't exist. In your case, it used to exist and now it doesn't, because you deleted it.

That has nothing at all to do with any commits that may or may not have been committed to that branch. Those commits are not lost, because you merged the branch into master before deleting its name, so you see them in the diagram.

If the question is why those commits appear in a straight line up to master rather than on a "railroad siding", it's probably because the merge to master was fast-forwarded.

Upvotes: 3

Related Questions