We have a branch pointing to the wrong place. We need to change that. The new CL is NOT a descendant of the old one. On the local repo I was able to do this using a "git checkout mybranch; git reset mybranch-new". However, it won't let me push this:
error: failed to push some refs to 'https://firstname.lastname@example.org/alterapartners/hwlibs.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
The error you're getting is just Bitbucket telling you that you forgot to include the "–force" flag in your push. And so the simple answer here is to just make sure to include that flag when you push!
For a more complicated answer, keep reading.
I wouldn't bother doing anything locally. Instead I would just update the remote branch directly using "git push --force", like so:
git push -f origin <commitId>:refs/heads/[BRANCH-TO-UPDATE]
That command basically says "make [BRANCH-TO-UPDATE] point to <commitId> NOW!" You need to add the "–force" flag if origin/[BRANCH-TO-UPDATE]'s previous commit-id is not an ancestor of the new <commitId> you're replacing it with (in other words, if you're rewriting history).
Often admins setup Bitbucket repos to reject history rewriting. If your repo is setup that way you will temporarily need to disable the pertinent hooks or branch permissions before you can proceed.
Note: if your branch is called "feature/TKT-123" then the push goes to: "refs/heads/feature/TKT-123". Sort of annoying that you have to include "refs/heads/" when specifying the target branch, but it seems to be necessary when using the "git push" command in this way.
Here's a concrete example:
git push --force origin 828dc7694fac1a5ded:refs/heads/testBranch
Of course there's still the whole problem of what do with any local versions of the old branch people have lying around. I would recommend they do "git fetch; git stash; git reset --hard origin/[BRANCH-TO-UPDATE]; git stash pop" before continuing any work in their local copies of the branch.
This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.Read more
Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda ...
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs