Git: Pull remote branch from someone else’s Fork

There can be a scenario where you would need to continue working on the work done by someone else on your team. In such a case, you can pull your team member’s fork branch and continue working on whatever is done in that team member’s branch. You can add your code changed and push it and your team member can pull it in his/her local setup.

To work on co-worker’s branch


> git remote add <coworker-username> git@github.com:<coworker-username>/<reponame>.git
> git fetch <coworker-username>
> git checkout --track <coworker-username>/<coworker-branchname>

Now, you will get all the recent changes made on your co-worker’s forked repo branch. You can add your code changes and push them. Your co-worker will be able to pull your changes.

Check the tracked repositories


> git remote -v

To work on your own branch

If you want to continue working only by yourself for the remaining part of the project/feature, then you can create a new branch from your co-worker’s branch.


> git remote add <coworker-username> git@github.com:<coworker-username>/<reponame>.git
> git fetch <coworker-username>
> git checkout -b <your-branch-name> <coworker-username>/<coworker-branchname>

Then, you can add and commit your code changes and push them to your origin repository.


> git add <filename>
> git commit -m <commit-message>
> git push origin <your-branch-name>

Hope this helps. Thanks.

References: