Manually create a Git fork

If I understand forking, it conceptually includes the following steps:

  • Mirror-clone source repo for target repo
  • Set the upstream remote to the target repo by pointing to the source repo
  • Some other things like email subscriptions, etc. (not important for this question)

Here's what it looks like:

Original <──upstream─── Forked (server) (server) ↑ β”‚origin β”‚ (local) 

The key difference from cloning is that these steps are server-side, not local. How to do replication manually, on git command line?

Here is what I have done so far:

  • Clone source repo to local repo
  • Modify the origin panel to indicate target repositioning
  • Add upstream remote reference to source repo

At this point, everything is set up on the local repo. I can synchronize changes between source and forked repositories using an intermediate local clone. So here is what I have:

 Original Forked (server) (server) ↑ ↑ β”‚ β”‚origin β”‚ β”‚ └───────upstream─── (local) 

Now, as I click this link to the server, i.e. make the source repo a remote remote server on the fork side on the server side to fit the first diagram?

Please note that this question is not specific to GitHub - I could also do this using BitBucket. Ideally, I should be able to do this on different sites. I read a lot of similar questions here on SO, but there is no clear answer.

+7
git bitbucket github git-fork
source share
4 answers

You can fork a project on Bitbucket using your API on the command line, but you need at least read access to the original project.

Syntax:

 curl -v --user {username}:"{password}" \ https://bitbucket.org/api/1.0/repositories/{accountname}/{repo_slug}/fork \ --data "name=mynewrepo" 

eg.

  • To deploy a projectABC project from an ABC account to your XYZ account named ProjectXYZ , use the following command

     curl -v --user XYZ:"XYZPASSWORDXYZ" \ https://bitbucket.org/api/1.0/repositories/ABC/ProjectABC/fork \ --data "name=ProjectXYZ" 

    see the Bitbucket documentation for more details.

  • Now clone this project on your local computer,

     git clone your_target_git_repository_path 
  • Go to the project directory and add a remote upstream that points to the source repository,

     git remote add upstream source_git_repository_path 
  • Now, at any time, to pull the changes from the original repository (say, from the main branch), use:

     git pull upstream master 

    and in order to direct local commits to the target repository on the server, use: git push origin master

  • And when your changes to the target repository are ready to merge with the source repository, create a Pull request either from the Bitbucket website or using the Bitbucket API: Pull Request

+7
source share

Steps to create a local copy of the repo pointing to the final forked repo, as you described in detail.

The next step is to create a forked repo. This can be done from the command line using the Github API - not git ; see fooobar.com/questions/25191 / ... for more information.

After that, a simple git push origin master perform manual forcing.

Note. Bitbucket also provides a REST API that allows you to create a branched repo from the command line.

0
source share

When you click on your fork, try this option: --mirror

https://git-scm.com/docs/git-push#git-push---mirror

This may mean that you need to specify the -mirror option when cloning to get deleted points in the local repo.

Alternatively, you can enable remote script customization in your repo and refer to it in the developer configuration guide for your project.

0
source share

For GitHub, apparently now you can do this using the hub CLI using the hub fork command. I have not used it, but based on the docs it looks like this:

 git clone git@github.com :some_user_or_organization/some_project.git cd some_project hub fork 

... and you will have two remotes: origin , which indicates the upstream, and one with the same name as your GitHub username, which indicates your new plug. (It would be nice if the hub also switched the remote names to "upstream" and "origin" respectively, but I don't think so.)

0
source share

All Articles