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.
git rebase develop
inside the issue
branch. But it said that it is already updated with the develop
branch.issue
branch, and it also said that it is up-to-date with that repo.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?
The correct approach is:
git fetch
git switch issue
git rebase origin/develop
Meaning:
develop
branch itself, the remote tracking branch origin/develop
is enough (and is updated by git fetch
)develop
(an integration branch) to another branch (like issue
): integrations branches are branches you are merging ("integrating") to, not from.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).