Search code examples
gitgit-branchgit-mergegit-rebasegit-workflow

How to get changes from a branch that I have been merging to it?


We are a team where we branch off from a WorkInProgress branch, to our own branch and all our work gets "dumped" into WorkInProgress.

When a dev is done with some work/feature, they commit to their branch and push to their remote. Then, they do "Pull Request" remotely from their branch to the remote WorkInProgress.

We have been doing this for a long time. Today, we want to "sync". So for example myself, I want to get all the developers' work from WorkInProgress branch, into my branch.

Would Git know the changes that are common (WorkInProgress has commits from my branch already) and exclude them when "merging back" to my branch?

How do I "update" my branch properly?


Solution

    1. Make sure you have the latest version of the local WorkInProgress branch (git fetch origin WorkInProgress:WorkInProgress)
    2. Checkout your own branch (git checkout OwnBranch)
    3. Merge the WorkInProgress branch into your own branch (git merge WorkInProgress), you may have to resolve conflicts.

    When you later make the pull request to merge your branch back in, git will correctly identify where to start comparing the branches from and which commits it needs to put in.