fork as organization after already forking in github

12,885

Solution 1

How about

  • Deleting your personal repository (making sure you've got a local clone/backup) by going to https://github.com/:your_login/:repo_identifier/admin then clicking the Delete Repository button in the Danger Zone.

enter image description here

  • Browsing to the upstream repository GitHub page (https://github.com/:upstream_login/:repo_identifier) should now display a Fork button.

  • Clicking the Fork button will display a dialog (similar to the one below) requesting if you're willing to fork to your personal area or your organization area.

    enter image description here

  • Once this is done, you can add to your local repository a remote pointing to the newly forked repository in your organization area.

$ git remote add your_organization [email protected]:your_organization/repo_identifier.git

UPDATE:

I may have found a (hackish) way to fulfill your request

  • Make sure you're logged in in GitHub
  • Open a new tab and go to https://github.com/:upstream_login/:repo_identifier/fork
  • This should display a page proposing to fork the upstream repository to your organization area.
  • Click on the button :)

Warning: this rely on an undocumented GitHub feature and this hack may stop working at any time. However, once the fork is created, even if the hack stops working, it is safe to think the fork should remain.

enter image description here

Solution 2

You can fork to an organization using curl & the github API. The below example will fork the faraday ruby gem to the "your_organization" organization:

 curl https://api.github.com/repos/technoweenie/faraday/forks \
 -d '{"organization": "your_organization"}'

Note: you will want to change "your_organization" to the actual name of the organization you want to fork to. You may also need to authenticate to successfully fork.

Forking instructions via github developer documentation:

https://developer.github.com/changes/2012-11-27-forking-to-organizations/

Solution 3

UPDATE

For some reason the url https://api.github.yourdomain does not redirect the requests to the latest API version, at least in our Github Enterprise. So none of the previous procedures work for me.

Following the latest documentation this is how you can do it using the latest API version which is v3 at this point.

curl -k -u "user":"password" https://github.com/api/v3/repos/USER/REPO/forks -d '{"organization": "YOUR_ORGANIZATION"}'

I've created a little function in bash to do it easier.

usage: git_fork_to_org <repo> <organization>

e.g $ git_fork_to_org rgcr/dotfiles my_awesome_organization

git_fork_to_org(){
    repo=$1
    org=$2

    [ $# -ne 2 ] && >&2 printf "usage: git_fork_to_org <repo> <organization>\n" && return 1

    printf "github user > "
    read -n gh_user

    printf "github password > "
    read -ns gh_password

    printf "${gh_user} > forking ${repo} to ${org}\n"

    curl -k -u "${gh_user}":"${gh_password}" \
        https://github.com/api/v3/repos/${repo}/forks \
        -d "{\"organization\": \"${org}\"}"
}
Share:
12,885

Related videos on Youtube

Ben
Author by

Ben

i'm a coder who likes to make stuff.

Updated on June 23, 2022

Comments

  • Ben
    Ben almost 2 years

    Is it possible to 'fork again' in github? I had forked a public repository, but then I became owner of an organization and I'd like to fork the same original repository again (not my fork). However, it seems that in order to choose to fork as an organization you can only do so by clicking on the 'fork' button, which because I had originally forked it, that button now says "your fork" to take me to my original fork, but doesn't let me choose "fork as organization."

  • Ben
    Ben about 12 years
    is that really the only way? i don't want to delete my fork, isn't there a way to have both?
  • nulltoken
    nulltoken about 12 years
    @Ben I've added another (tested) workaround. Use it while it works :)