Dhaval Chheda
Dhaval Chheda

Reputation: 5167

git issues creating a PR from the forked repo to the main repo

This is the first time I am contributing to an open source project and I have this git issue. I forked the repo originally then deleted it and then re forked it. I checked out a dev branch from my forked master and did some work and now I want to create a PR to the main repo. But it says entirely different commit histories.

I tried the below steps but did not help me

git remote add upstream https://github.com/some_user/some_repo
git fetch upstream
git checkout master
git reset --hard upstream/master  
git push origin master --force

Any assistance on this will be appreciated

git log -n10 upstream/master returns below snapshot

enter image description here

git log -n10 origin/dev returns below snapshot

enter image description here

git log -n10 origin/master returns below snapshot

enter image description here

Upvotes: 1

Views: 326

Answers (1)

Ferrybig
Ferrybig

Reputation: 18834

Based on the second screenshot you posted, it seems like you followed the following steps:

You when to either the fork or the original GitHub repo, then download a zip of it, you did your changes, an that did git init, and forcefully pushed this to your fork.

What basically happened is that by the process of doing this, you only copied the files to your fork, and not the full history.

Since now we know what happened, we can start fixing the issue, and since the original repository isn't very busy with traffic, it becomes easier to fix now.

Because we want to keep the original files, but merge the history back in, we need to do the following steps:

  1. Make a backup of the original directory (its always wise to make backups any time)
  2. Make a new project that has the original files & history: git clone https://github.com/your_name/your_fork
  3. Copy the files back from your backup and move them to the new project, making sure to exclude the .git directory.
  4. Run git status, this should show only the files you changed depending on the base state 1
  5. If everything is correct, we need to "upload" the files now
  6. Add your changed files to git: git add .
  7. Commit the changes: git commit -m "Adding my feature" (I suggest you use a more descriptive commit message)
  8. Push the changes to your fork: git push

Now, go to the original GitHub repository, and try to make a PR there, it should be fine now.

1. If git status does not show any files changed, its probably because you accidentally copied the .git directory from your backup

Upvotes: 2

Related Questions