If I understand forking, it conceptually involves the following steps:
This is how 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 do I replicate this manually, on the git command line?
Here's what I've done so far:
At this stage, I have everything set up on the local repo. I can sync changes between the original and forked repos using an intermediate local clone. So this is what I have:
Original Forked
(server) (server)
↑ ↑
│ │origin
│ │
└───────upstream─── (local)
Now how do I push this link to the server i.e. make the original repo an upstream remote of the server-side forked repo, to match the first diagram?
Note that this question is not GitHub-specific - I might also want to do this with BitBucket. Ideally, I should be able to do this across sites as well. I've read lots of similar questions here on SO, but there's no clear answer.
You can fork a project on Bitbucket using their API on command line, but you need at least read access to source project.
Syntax is:
curl -v --user {username}:"{password}" \
https://bitbucket.org/api/1.0/repositories/{accountname}/{repo_slug}/fork \
--data "name=mynewrepo"
e.g.
To fork a project projectABC
from an account ABC
to your account XYZ
with the name ProjectXYZ
, use the following command
curl -v --user XYZ:"XYZPASSWORDXYZ" \
https://bitbucket.org/api/1.0/repositories/ABC/ProjectABC/fork \
--data "name=ProjectXYZ"
see Bitbucket documentation for more details.
Now clone this project on your local machine,
git clone your_target_git_repository_path
Go to your project directory and add remote upstream
which will point to the source repository,
git remote add upstream source_git_repository_path
Now, at anytime to pull the changes from source repository (say from master branch), use:
git pull upstream master
and to push your local commits to your target repository on server, use: git push origin master
And when your changes on target repository are ready to be merged with the source repository, create a Pull Request either from Bitbucket website or using Bitbucket API: Pull Request