Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - Forking without Github

Is the function of "forking" specific to github? or is there a purely git process for creating "copied" child repositories that can pull updates from the parent? If so, how?

EDIT : I must be confused about what git clone does then. It was my understanding that git clone is what I do on my machine to get a local copy of the repository to make changes to, commit, and push from. We are currently hosting our repos with gitosis. So if I wanted to accompish a 'fork' I would clone the repository on the gitosis server itself (at the origin)? Would that create a new git address?

like image 548
jondavidjohn Avatar asked Jan 18 '11 19:01

jondavidjohn


4 Answers

# clone wanted repo
git clone https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git

# cd into created folder
cd ORIGINAL_REPOSITORY

# rename `origin` remote (original repo url) to `upstream`
git remote rename origin upstream

# add your remote repository as `origin`
git remote add origin https://github.com/my_user/my_repository.git
    
# when want to pull from upstream just
git pull upstream main

# when want to create upstream pull-request just
# https://git-scm.com/docs/git-request-pull
# commit-hash - from where to start pull request
git request-pull commit-hash [email protected]:my_user/my_repository.git
like image 118
iamandrewluca Avatar answered Sep 21 '22 15:09

iamandrewluca


You probably don't want to actually do this. Branches in git are very nice and lightweight, and there really isn't a reason why you shouldn't just make a branch in the repository that you have right now. The only reason I can think of to do this with a gitosis repository is in order to make access control interesting, if you have a continuous deploy or something which pulls from one gitosis repository and you want to give commit access to the same code but don't want them to be able to write to the one that is deployed. For all other uses, you should just make a branch with git branch and do all your work on the branch. Alternately you might want to clone a github repository and then have a team work on it within your central gitosis architecture.

Given that pre-warning, the easiest way to create a "fork" in the way that you describe, is to make a separate repository on the gitosis server. So set up another repository with the other name - for example if your original repository is gitosis@server:repo1.git you would set up another one at gitosis@server:repo1-fork.git. Add whatever users you want to have access.

Then you would clone the repository: git clone gitosis@server:repo1.git which puts a full copy of the repo into ./repo1. To copy it from your local version to the forked repository, you can do a git push gitosis@server:repo-fork.git --mirror.

like image 43
jamuraa Avatar answered Sep 19 '22 15:09

jamuraa


Forking on Github is the equivalent of a simple git clone, though in the case of the fork it's more like a git clone --mirror.

like image 36
Lily Ballard Avatar answered Sep 20 '22 15:09

Lily Ballard


Any time you git clone a repository, you've effectively created a fork. The only thing GitHub's fork functionality does is make the clone a GitHub repo, with a Web page and graphs and stats and all that good stuff.

Also, when you clone a repository, Git automatically makes the original repository the default “upstream” repo (the remote called origin). So, out of the box, git pull without arguments should pull straight from the original.

like image 33
Luke Maurer Avatar answered Sep 20 '22 15:09

Luke Maurer