FallonPy
FallonPy

Reputation: 17

How can I syn the forked repository's history with the main one?

I am a newbie with git and I just forked a repository and did some changes to it. After a while, the main repository's history changed. How can I make, the two repos have the same history?

I know that there will be problems with pull requests if the histories are not the same.

Upvotes: 0

Views: 215

Answers (1)

yi fan song
yi fan song

Reputation: 427

There are 3 ways you could do that:

  1. You can merge the upstream (that means the repository on github for example) with your current branch so you can then push your changes upstream without issue.

Do a git fetch then you will want to merge what you fetched with your current working branch, that can be done with git merge origin/master if you're on master. Then you might have merge conflicts to fix before you can commit and push your changes upstream.

  1. You can make a branch and commit your current changes there, then pull upstream to keep your master branch up to date, then merge your new branch into your master either on your machine then push the changes or using your repository's web manager's tool (e.g.: github pull requests), this requires that there are no conflicts between the 2 branches.

For this one, first branch off using git checkout -b <branch name>, then commit and push your changes. After that, if you want to do it on your machine, you'll have to update master with the same steps than the first way to do it, just make sure you are on master by doing git checkout master. After that you can merge the changes you put on another branch back with git merge <branch name>. Fix the merge conflicts then commit and push. If you want to do it on github or your web repo of choice, you have to first merge master into your new branch if there are merge conflicts: git fetch then git merge origin/master, fix the conflicts, commit and push, then use the web ui to do the pull/merge request.

  1. You can stash your changes, update your branch, then get your changes back from the stash

Stage your changes with git add then git stash and then update your local branch to the upstream like in the first method, then use git stash pop, fix your conflicts, commit, and push.

Upvotes: 1

Related Questions