简体   繁体   中英

How to take changes from one remote branch to other remote branch

I'm working on a project and I cut a branch from a release_branch let's call my branch branch_A . My colleague also had cut another branch from same release branch and lets call that branch_B . We are working on the same file and section hence to avoid any merge conflicts I wanted to take changes from branch_B to my branch_A . Changes of branch_B has already been merged into that release_branch from which we had cut our branches earlier.

Can somebody tell what should I do? I've tried pull but it didn't work. Also I switched to the release_branch and took pull and changes were there but as soon as I switched to my branch_A the changes were gone. Please help.

First, make sure that you commit all changes to your branch_A and if you are concerned about losing your work as part of the process, create a new branch at branch_A (eg branch_A_old ).

Since you will eventually be merging back to release_branch , you can use one of the following approaches:

  1. Checkout branch_A , if not already, then pull from remote_name/release_branch into branch_A using git pull --no-rebase remote_name/release_branch . This will create a merge commit, merging the latest release_branch , including changes made by branch_B into your branch. If there are any conflicts, you will have to resolve them and perform a commit to complete the merge.
  2. Checkout branch_A , fetch remote_name/release_branch , then merge remote_name/release_branch into branch_A . This is basically the same as method 1, but broken into two steps.
  3. Checkout branch_A , fetch remote_name/release_branch , then rebase branch_A using remote_name/release_branch as the upstream branch. Alternatively, you can use use git pull --rebase remote_name/release_branch to combine the fetch and rebase into one step.

Methods 1 and 2 will keep the merge as part of the history and method 3 will update all of the commits in your branch so that your branch begins at the latest commit of release_branch .

Methods 1 and 2 are usually easier, although this is debatable, but method 3 will provide a cleaner history. If you do use method 1 or 2, you can always perform a squash later to clean up the history.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM