'Git rebase when master has been changed

I created a branch feat/add-access from master, made a single change. Then I tried to rebase to master, but I realized changes have been made to master, so I got:

Your branch and 'origin/feat/add-access' have diverged,
and have 1 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

nothing to commit, working tree clean

Then I removed my changes with:

 git fetch origin
 git reset --hard origin/master
 HEAD is now at 9cc1c2f Jenkins Pipeline PR Merger

HEAD is now at 9cc1c2f Jenkins Pipeline PR Merger

Which is OK, because 9cc1c2f is the last commit on master. I also can see my changes has been removed.

Now I have:

project git:(feat/add-access) git status
On branch feat/add-access
Your branch and 'origin/feat/add-access' have diverged,
and have 2 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

nothing to commit, working tree clean

Then I do:

➜  project git:(feat/add-access) git rebase master             
Successfully rebased and updated refs/heads/feat/add-access.

But I still get diverging branches:

project git:(feat/add-access) git status
    On branch feat/add-access
    Your branch and 'origin/feat/add-access' have diverged,
    and have 1 and 1 different commits each, respectively.
      (use "git pull" to merge the remote branch into yours)
    
    nothing to commit, working tree clean

git pull doesn't work.

fatal: Not possible to fast-forward, aborting. 

git log shows no issue. In local, I am in the desired state, a copy of master branch.

I could simply delete remote feature branch, and just push it again, but I have an open PR on it, it may affect it, so I won't do it.

What should I do ? I'm a bit newbie with rebase, and I don't want to mess up the master branch !



Solution 1:[1]

I think I could solve it, what I did was to rebase local feat branch changes into distant one with:

git rebase origin/feat/add-access feat/add-access
git push

and made a fixup to add my changes

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Juliatzin