Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Bitbucket - Syncing Branch with another Branch

This may be a duplicate of How to keep a git branch in sync with master (I assume I can just replace Master with the other branch), but it's vital that this works and doesn't merge the wrong way around so I need to make sure.


There was a branch called v1, and I created a branch off of that called v1_adminui. I've made around 10 commits to my branch v1_adminui, but a major improvement to another part of the project has been made in v1, so I want to Sync that change with my current branch.

I believe the following would do it:

git checkout v1
git pull
git checkout v1_adminui
git merge v1

Please can you confirm if this is correct? If not, any help would be appreciated on how to accomplish this.

like image 856
Gary Avatar asked Mar 16 '23 09:03


1 Answers

Since you are the only one working on this branch, you should use rebase instead of merge.

# Get the base branch
git checkout v1

# Pull in any changes to make sure you have the latest version
git pull

# Check out your branch
git checkout v1_adminui

# Rebase your changes on top of the v1 changes
git rebase v1

# Optionally push your rebased branch
git push origin v1_adminui

You might have to use the --force option when pushing in the last step. Since you're rewriting the branch's history with the rebase, the remote branch will have a different history. Only do this if no-one else is using this branch!

like image 147
nwinkler Avatar answered Mar 28 '23 04:03