4

I created a PR for this issue, after a while the main repository is updated with new accepted PRs and my fork is behind the main repository.

So now I tried to synchronize my Forked Repositoy, but that's not the end of the problem I have to sync my commits or log with the main repository.

How do I synchronize my forked repository time-line/logs with the main repository.

Chinmaya B
  • 375
  • 1
  • 5
  • 17
  • Probably with a rebase on top of upstream/master. I am commuting right now, and on my phone. I will answer when I get back. – VonC Jun 16 '17 at 07:50
  • Oh okay...The problem is with the updated commits, they are glued into a single commit, which appears as a single commit(combo of 10 or more commits) in fork log. I just want to avoid re-fork, maybe separating each commit from the single 'merge' commit would work here. – Chinmaya B Jun 16 '17 at 07:54

1 Answers1

3

The problem is with the updated commits, they are glued into a single commit, which appears as a single commit(combo of 10 or more commits) in fork log

That is expected, since you have pulled (fetch+merge)

I would advise you to locally remove to remove that merge commit, and rebase (ie replay your commits) on top of upstream/master (with upstream being the remote name for the original repo)

Plus, I would have isolated those changes in a dedicated branch, but since you have started the PR from master, let's stay on master.

Make sure you don't have any local work in progress.

cd /path/to/local/repo
git remote add upstream <Repository URL>

Check the output of git remote -v: you should see upstream and origin, with origin referencing your fork.

git log # make sure master HEAD is at the right commit
git fetch upstream
git rebase upstream/master
# test if everything is still working
git push --force
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Is it going to affect my PR commit as that commit is more costly than all of this – Chinmaya B Jun 16 '17 at 19:12
  • @ChinmayaB No it will not: the `push --force` will re-upload your commits, and the PR in progress will automatically update itself with those new commits. – VonC Jun 16 '17 at 19:13
  • @ChinmayaB All you need to do before pushing (push --force) is make sure you do see locally your commits on top of the upstream repo up-to-date. If what you see is correct, and working, you can push --force to your fork, and the PR will take that into account automatically. – VonC Jun 16 '17 at 19:14
  • Git is not able to get upstream repository it says...`fatal: 'upstream' does not appear to be a git repository fatal: Could not read from remote repository. ` – Chinmaya B Jun 16 '17 at 19:19
  • @ChinmayaB Sorry, I assumed you had upstream already. Let me edit the answer. – VonC Jun 16 '17 at 19:19
  • No I've had an upstream I followed your answer https://stackoverflow.com/questions/3903817/pull-new-updates-from-original-github-repository-into-forked-github-repository/3903835?noredirect=1#comment76154945_3903835 – Chinmaya B Jun 16 '17 at 19:20
  • @ChinmayaB Well, I have edited the answer anyway: check if the command I have added will help – VonC Jun 16 '17 at 19:21
  • I used `git reset` command and now I cannot retrieve my old commit! – Chinmaya B Jun 21 '17 at 18:50
  • If you have committed, they're not lost: see git reflog – VonC Jun 21 '17 at 18:52
  • You can create a new branch at that sha1, and you will see your commits there – VonC Jun 21 '17 at 19:16
  • The `rebase` command manages the rewinding and putting new comments. The problem was created due to the `reset` you should remove that from answer. `rebase` will automatically perform reset and then again rebase operations. – Chinmaya B Jun 22 '17 at 19:30