We use a Git branch for our work; let's name it Branch_A
How do I do that?
Hi @pierre.rouleau
You need to do a rebase onto Branch_A:
git checkout Branch_Bgit rebase Branch_Agit push origin Branch_B --force
Thanks @Saxea _Flowie_ . Will try this.
Always a little nervous to try things like that in a real, super utilized, BitBucket hosted repo environment. I'll read more on rebase and I'll try it in a set of test repos first.
Is there anything I should be watching for that could cause problems?
You can create a backup of your branch before rebasing and also check the log to make sure it looks like how you expect before pushing:
git checkout Branch_Bgit checkout -b Branch_B_backupgit rebase Branch_Agit log --graph --oneline --allgit push origin Branch_B --force
The critical part is the push force which will rewrite the branch remotely.
One thing that can go wrong is if you have conflicts. Then you need to resolve them and do a `git rebase --continue`
Lastly, the commits in this branch will be re-created, so if it's been shared with other team members, you will need to let them know that it has been rebased. So they can adjust their local copies too, by pulling your new commits. There are different ways to handle this, but possibly the simplest is to make sure everyone pushes their changes. You pull their changes, rebase and push. They can then reset their branches: `git reset --hard origin/Branch_B`
I'm not worried about Branch_B. I'm worried about Branch_A. So I assume that as long as no push is done, all changes are local and as you say the push --force is the critical point. The problem I see is that there's people all over that might be doing something in the Branch_A as I push --force.
I might not even know of their existence... And for sure can't ask them to do anything specific.
The Git repo is hosted on a BitBucket corporate server.
The problem originates from the fact that I created Branch_B sooner than I should have done *and* that the Branch_B is tied to a Jira ticket on which I'd push my changes and create a pull request to get the commit approved.
Is there a way to "disconnect" the branch (Branch_B in this case) from the Jira ticket, recreate a new branch, say Branch_C, and "connect" that Branch_C to the Jira ticket?
For the moment my work-around was to create a sub-task of the Jira ticket, create a new branch where I committed my changes, pushed them and create the pull request to Branch_A. But that requires an extra Jira ticket.
It looks like you're new here. Sign in or register to get started.