fork as organization after already forking in github

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/


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}\"}"
}

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