Search code examples
gitgit-workflow

why do I have to pull my own branch from remote before push if I rebase modified master ontop of my banch locally?


why do I have to pull my own branch from remote before push if I have rebased modified master ontop of my banch localy?

I was working on my development branch, meanwhile somebody updated master branch, so I rebased master branch on my development branch and got latest changes from master branch on remote.

Now when I do git status I get message saying My devbranch has divereged from origin/devbranch.

the git status suggest to git pull. by doing so I am prompted to ammend the merge message.

after that I can push. if i do not do the above and just do git push it gets rejected. I was under impression that if I have changes in my development branch and I include changes from master then it should not restrict becuase HEAD of my development branch locally has moved, and upstream is following my branch locally !


Solution

  • so I rebased master branch on my development branch and got latest changes from master branch on remote.

    This makes no sense, and you normally would not rebase master on some feature branch. What I think you actually did is the reverse, namely to rebase your development branch on master to bring in the latest changes.

    When you completed the rebase, you rewrote the history of your development branch. What this effectively does is to create a situation where your local development branch is now diverging from the remote version. The typical way to remedy this is to just force push:

    git push --force origin development
    

    This will overwrite the remote development branch with the rebased version.