DEV Community

Cover image for How do you work with someone else's fork?
David MacEachern
David MacEachern

Posted on

How do you work with someone else's fork?

This might be useful if you want to work with a fork that someone else has started. I found a solution on Stackoverflow which described how to get their work into a branch that can be worked with. [1]

They had forked the project we were talking about on Github, and in their local they checked out a branch of their own to work on, done some awesome work, and pushed their branch back to their fork on Github.

Step 1: Fork our own repository

We can click on the fork button to make a repository of our own that we can work with.

alt text

Step 2: Clone our own repository to our local machine

wsl@DESKTOP-DCRMGFD:~$ git clone
Cloning into 'rocket-lamb'...
remote: Enumerating objects: 206, done.
remote: Total 206 (delta 0), reused 0 (delta 0), pack-reused 206
Receiving objects: 100% (206/206), 45.74 KiB | 564.00 KiB/s, done.
Resolving deltas: 100% (120/120), done.
Enter fullscreen mode Exit fullscreen mode

Step 3: Get the work that the other person has started into our fork

I ran the following:

$ cd rocket-lamb
$ git remote add other
$ git fetch other
$ git checkout -b add-other-changes
$ git pull other rocket-0.5
Enter fullscreen mode Exit fullscreen mode

The output looked like:

wsl@DESKTOP-DCRMGFD:~$ cd rocket-lamb
wsl@DESKTOP-DCRMGFD:~/rocket-lamb$ git remote add other
wsl@DESKTOP-DCRMGFD:~/rocket-lamb$ git fetch other
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 15 (delta 9), reused 15 (delta 9), pack-reused 0
Unpacking objects: 100% (15/15), 3.58 KiB | 215.00 KiB/s, done.
 * [new branch]      master     -> other/master
 * [new branch]      rocket-0.5 -> other/rocket-0.5
wsl@DESKTOP-DCRMGFD:~/rocket-lamb$ git checkout -b add-other-changes
 pull other rocket-0.5Switched to a new branch 'add-other-changes'
wsl@DESKTOP-DCRMGFD:~/rocket-lamb$ git pull other rocket-0.5
 * branch            rocket-0.5 -> FETCH_HEAD
Updating 6b28c56..6a995b1
 Cargo.toml            |   9 +++--
 src/        |  26 ++++++++-----
 src/        | 220 ++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------
 src/    |  56 +++++++++++++-------------
 tests/   |   2 +-
 tests/ |  11 +++---
 6 files changed, 155 insertions(+), 169 deletions(-)
Enter fullscreen mode Exit fullscreen mode

Step 4: Make some changes then push to Github

Once changes have been committed locally they can be pushed to our remote for others to benefit from.

$ git push origin HEAD
Enter fullscreen mode Exit fullscreen mode

They can then add our fork as an other remote on their local so they make use of the work we did, if what we did was correct of course!

Wrapping up

Thoughts on this? Have you done something similar or maybe there is a better way to go about working with a fork?

If this helped don't forget to go to Stackoverflow and upvote the solution provided there!


[1] Git pull from someone else's fork

Top comments (1)

dbanty profile image
Dylan Anthony

Oh hey that's me! Thanks for collaborating with me on this ☺️. I'm now using these instructions to pull your latest changes into my fork to keep working!