ChronoTrigger
ChronoTrigger

Reputation: 8617

Git: synch a branch with the original forked master

I forked a GitHub project into my own repository. My repository contains only a "master" branch in which I commit my own code. The forked project contains a "master" branch only as well.

From time to time, I find and fix some bug in the original code and I want to create a pull request so that the developers of the original project can add the fix. However, I don't want to add to this pull request all the code I changed, just the fix.

I think the correct way to proceed here is to create a new branch in my repository, synchronize this with the original forked master, commit the fix and create the pull request. My question is: how can I create a branch and get rid of all my commits to synchronize it with the forked master?

As an aside, is this actually the most practical way of doing this?

Upvotes: 0

Views: 162

Answers (2)

Pianov
Pianov

Reputation: 1663

I can suggest next steps for solving your problem:

  1. configure remote address to the forked master

git remote add upstream <url_to_forked_project>;

  1. fetch all changes from upstream

git fetch upstream;

  1. create new fix branch and download forked master

git checkout upstream/master -b fix;

  1. apply you fixes

git cherry-pick <commit_hash>; or make a new commit somehow

  1. push your changes to your remote github repository

git push origin fix:fix;

git branch -d fix; - remove the unused branch

  1. and after that you can create a new pull request from your remote fix branch

Upvotes: 1

Bhavya Shaktawat
Bhavya Shaktawat

Reputation: 2512

You can create a branch and revert all the commits using git revert command that you want to get rid of.

And then sync forked repository to get all the changes done in the upstream repository.

Upvotes: 2

Related Questions