2

I have a github repo and I am working on the site, I don't know how to do command line stuff.

So I have a branch I made commits too. And I see it can be deleted. This is kind of nice. I always do small unit tests and just want to delete it. So if I do delete a branch is all traces and history of it gone?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Noitidart
  • 35,443
  • 37
  • 154
  • 323

1 Answers1

2

If you don't have a local repo anymore (meaning you cannot get your deleted branch through the local git reflog and push it back to GitHub), you still can retrieve (for a limited time, 90 days by default), your deleted branch from the GitHub repo itself.

See the GitHub Events API.
Those events are limited in time, so "all traces and history of it gone?": yes, eventually.

curl https://api.github.com/repos/<user>/<repo>/events

As described in this blog post, you will get a JSON payload which will include any push event you ever made, including your old branch:

    "id": "1970551769",
    "type": "PushEvent",
    "actor": {
      "id": 563541,
      "login": "<user>",
      "gravatar_id": "<id>",
      "url": "https://api.github.com/users/<user>",
      "avatar_url": "<url>"
    },
    "repo": {
      "id": 9652839,
      "name": "<user>/<repo>",
      "url": "https://api.github.com/repos/<user>/<repo>"
    },
    "payload": {
      "push_id": 303837533,
      "size": 1,
      "distinct_size": 1,
      "ref": "refs/heads/<branch>",  <============================
      "head": "a973ddd28d599c9ba128de56182f8769d2b9843b",
      "before": "4ef3d74316c04c892d17250f0ba251b328274e5f",
      "commits": [
        {
          "sha": "384f275933d5b762cdb27175aeff1263a8a7b7f7",
          "author": {
            "email": "<email>",
            "name": "<author>"
          },
          "message": "<commit message>",
          "distinct": true,
          "url": "https://api.github.com/repos/<user>/<repo>/commits/384f275933d5b762cdb27175aeff1263a8a7b7f7"
        }
      ]
    },
    "public": false,
    "created_at": "2014-02-06T14:05:17Z"
}

You can then fetch, using that specific commit 'a973ddd28d599c9ba128de56182f8769d2b9843b', make a branch locally and push it back to GitHub!

git fetch origin a973ddd28d599c9ba128de56182f8769d2b9843b:refs/remotes/origin/yourOldBranch
git checkout -b yourOldBranch
git push
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Oh wow this is such great info. Thanks man. So to verify/sum it up after 90 days it is permanently deleted huh meaning all traces? And before those 90 days it is possible to get it back. – Noitidart May 25 '14 at 19:31
  • 1
    @Noitidart 90 days is the default before `gc` (garbage collector) is run. But GitHub might have a different policy. – VonC May 25 '14 at 19:34
  • Thanks for your detail. I read the blog and your detail on using the `head` value is great to emphasize. Thanks again man! – Noitidart May 25 '14 at 19:35