Search code examples
gitgit-pull

Git - Update older open feature branch


After the holiday I would like to continue working on my open ticket. I already started working on a feature ("feature/my-new-feature") locally before the holiday. After one week my colleagues have already merged their features into the master. Since I want to avoid later merge conflicts, I want to update my feature branch. However, I am unsure which update strategy to use. Two approaches are going through my mind.

1.

git checkout master
git pull
git checkout feature/my-new-feature
git merge master

2.

git pull origin/master

Probably both strategies work. Are there advantages and disadvantages to both ways that should be considered?


Solution

  • I usually rebase on master, i.e. replay my commits on top of the master:

    1. add and commit everything in the feature branch,
      git add ...
      git commit -m "..."
      
    2. update the local master,
      git checkout master
      git pull
      
    3. rebase the feature branch on the master
      git checkout feature/my-new-feature
      git rebase master
      

    What you are proposing in 1. is updating your master and merging it to your branch. It is not wrong at all but it can create messy history with merge commits. You can read about the difference e.g. here: https://blog.git-init.com/differences-between-git-merge-and-rebase-and-why-you-should-care/

    Your 2. is updating your remote tracking branch and merging that into your branch (pull does fetch and merge). It does exactly what you asked for: get the state on remote and integrate it to your branch. But it is not what you usually want: update master and origin/master too. There is nice explanation here and here:

    https://stackoverflow.com/a/18137512/12118546

    https://stackoverflow.com/a/8690791/12118546