Home > OS >  git rebase "already up to date" when I know I am behind
git rebase "already up to date" when I know I am behind

Time:12-24

git switch develop
git checkout -b <branchName>
(do work here)
npm run lint/prettier/test
git stash
git rebase develop
git stash pop
git commit -a -m ''
git push origin <branchName>

I'm having this issue when I'm working on my branch and the next day I try to rebase before I commit "Current branch is up to date." and when I commit bitbucket says I'm like x commits behind sync now.

Why an I having these issues every time and what can I do to fix this? This is my git command flow.

The git rebase never works and always says I'm up to date. The solution I've been doing is just cloning the repo every single time and copy pasting my changes before commit/pushing. Halp me!

CodePudding user response:

When you do

git rebase develop

then develop refers to your local develop branch. If develop has been changed on the remote repo you should first integrate those changes into your develop. I.e.

git switch develop
git pull
git switch <branchName>
git rebase develop

Or alternatively a little faster without updating local develop first

# stay on <branchName>
git fetch
git rebase origin/develop

CodePudding user response:

You can do the following likewise:

git fetch --all
git switch -c <branchName> origin/develop  # the last argument is a start-point (so you set your branch on top of fresh origin/develop in one go)
(do work here)
npm run lint/prettier/test
git commit -a -m ''
git fetch --all && git rebase origin/develop  # since some time might have elapsed you can once again update yourself onto fresh origin/develop to be 100% sure
git push -u origin HEAD  # -u: I let myself also track our new remote branch (with 'HEAD' you don't have to type its name, it will be named automatically after the local one)

Note that the local develop branch we don't even use in this workflow. You can always fetch origin/develop and treat it as your anchor point.

Another note is that playing with git stash is pointless here. If you encounter conflicts on the fresh rebase you will have to resolve them anyway (no matter on rebase or on stash pop).

  • Related