2

I forked a repository from some other person. I am working on a branch develop on my forked repo. I check out a new branch from it named issue. I did some changes in the new branch issue and pushed it.

Then I realized that the develop branch in the remote repo got updated, and so I pull the changed into my local branch develop which just deleted some of the files. Now I want to merge those changes into the issue branch.

  1. I did git rebase develop inside the issue branch. But it said that it is already updated with the develop branch.
  2. I also tried pulling directly from the remote repo inside the issue branch, and it also said that it is up-to-date with that repo.
  3. I tried git merge develop similar to the rebase command, and it also gave the same result.

I have checked that those files are already being tracked by git.
I don't want to manually delete those files.

I did git fetch origin develop from the remote repo and then git reset --hard HEAD inside the issue branch, which deleted the changes I made in other files.

What is the problem here, and can someone suggest an alternative to this without losing changes and without creating a new branch?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250

1 Answers1

0

The correct approach is:

git fetch
git switch issue
git rebase origin/develop

Meaning:

  • no need to update the local develop branch itself, the remote tracking branch origin/develop is enough (and is updated by git fetch)
  • no need to merge develop (an integration branch) to another branch (like issue): integrations branches are branches you are merging ("integrating") to, not from.
  • as long as the issue branch did not update the files deleted in the develop branch, those files will remain deleted.

Note: With Git 2.23+ (Q3 2019), git checkout is replaced here with git switch (presented here).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250