3

I want to simulate forking (as GitHub does it) a repository.

Essentially I want a local copy of a repository that is already hosted on GitHub, that I can push to and use as the remote in a project I will develop.

I don't want to directly clone the GitHub repository, because I don't have push access. However, I do want a remote (the "fork") that I will have push access to, because I want to keep a copy of my source in a more central location

  • in case anything happens to my development environment
  • for when I switch development environments

I think the "fork" can be created with either

  • git clone --mirror https://github.com/user/repo
  • or git clone --bare https://github.com/user/repo

but I am not clear on the differences between --mirror and --bare: I don't know which to use. And there might be a better solution entirely.

Then when I have "forked" it, I would like to clone the "fork" to where I will actually do development.

What's the most sensible way to do this?

theonlygusti
  • 11,032
  • 11
  • 64
  • 119
  • 1
    Just clone it and then clone the clone again. – tkausl Sep 25 '19 at 11:01
  • Possible duplicate of [What's the difference between git clone --mirror and git clone --bare](https://stackoverflow.com/questions/3959924/whats-the-difference-between-git-clone-mirror-and-git-clone-bare) – mimikrija Sep 25 '19 at 11:09
  • [This answer](https://stackoverflow.com/a/3960063/7629206) explains in great detail the differences between `--bare` and `--mirror` options. – mimikrija Sep 25 '19 at 11:11

1 Answers1

1

I wanted to do something similar too. You already got the answer indeed from @mimikrjia . However, if I were to give you more details I would recommend the following workflow based on my experience: In my case I have no remote repository my friend and I manage a collection of scripts on our private network.

  1. create a bare git repository that would be your remote: git init --bare would do the job for you.

  2. create another bare repository that would be the forked repository (proxy in my case) using the same command.

  3. set up the forked repository:

    git remote add origin

  4. create a normal repository and set it up with

    git init git remote add origin

  5. Use git-hooks to automate your workflow and enjoy!!!

The final result in my case: enter image description here

  • What git hooks did you set up for this case? – theonlygusti Feb 05 '23 at 11:41
  • In my case I have a master branch and feature branches. So for every feature branch I want to have the exact scripts I need, as well as I want to keep the features branches related to the master branch (we preferred not to use orphan branches). Therefore, I used mainly a pre-commit hook that retrieves all the deleted files from the master branch and add them to the commit. Also, we added a post-commit hook to remove those files after the commit is done(we did this because we dealed with loads of files). Yet, the main hook is post-push that synchronize the changes with the master branch. – Kotbi Abderrahmane Feb 05 '23 at 12:46