46

I've found a repository on GitHub I would like to fork - but not the current version.

I want to fork the repo as it was quite a few commits back - is this possible? The repo has not marked any releases, so I'm not sure how to do this. I could obviously copy the code as it was in that commit, but I would prefer to fork, as then I get the link back to the original repo.

ACarter
  • 5,688
  • 9
  • 39
  • 56
  • 7
    Why not fork and just create a branch from that previous revision? – Frank Osterfeld Oct 06 '13 at 20:56
  • @Frank I guess so... I'd just like to be working on the master, as the branch would then be the main version, and the master would be pointless. – ACarter Oct 06 '13 at 20:59
  • I would basically want my whole fork to be just the branch... – ACarter Oct 06 '13 at 20:59
  • 1
    You could just rename the master branch and create your own. http://stackoverflow.com/questions/1526794/how-to-rename-master-branch-in-git – kapex Oct 06 '13 at 21:02
  • Doing weird things to your repo prevents you from pulling in upstream changes later and sending back pull requests. Don't see much of a point in messing with that. – Frank Osterfeld Oct 06 '13 at 21:05
  • possible duplicate of [How do you roll back (reset) a git repository to a particular commit?](http://stackoverflow.com/questions/1616957/how-do-you-roll-back-reset-a-git-repository-to-a-particular-commit) – random Oct 06 '13 at 22:49

2 Answers2

48

You can only fork the current repository.

You can reset the forked repository's master branch to an earlier commit though, making it look like as if you had forked it at that point.

See: How can I rollback a github repository to a specific commit?

If you reset every branch, it effectively resets your repository to an earlier state of the original repository (with exception of branch-independent data, like configuration, hooks etc which are not reset). Since it's possible that not all branches contain the commit from the master branch, you might need to look up commits by date for each branch, to reset them to the last commit before the commit from which you want to fork.

kapex
  • 28,903
  • 6
  • 107
  • 121
0

I was also unable to do this using github, but Sourcetree handled it perfectly.

Switched to the desired branch. Found the commit that I wanted as the head of my new branch and right clicked. Selected "branch." My commit was already selected. Name this new branch, create, and push.

Can also be done by selecting the "branch" button. You then select the commit that you want as your new head, give it a name, and create it.