How to move my new branch to the latest commit in master branch?

I created a new branch from master branch two days ago. One of my team mates checked in few changes to master branch, instead of the new branch (it should be in both master and the new branch). Now, I want to move the origin of my new branch to the latest commit in master.

I have commits and branches as shown below:

  • setting up git instaweb with nginx
  • Git isn't fetching upstream data?
  • git merging only recent changes from one repository to another which is an unrelated snapshot (not a clone)
  • Howt to tell emacs VC that I want a file to be managed by git not by svn when the file is under both version systems?
  • How do I run a command on all files from git ls-files?
  • How git makes branching not to be feared?
  •                  C4      <-- New branch
                    /
    C0 - C1 - C2 - C3 - C5   <-- Master
    

    What I want is:

                         C4  <-- New branch
                         /
    C0 - C1 - C2 - C3 - C5   <-- Master
    

    I tried git merge and it didn’t work.

  • How do Asp.Net.Mvc git tags correlate to the git revision?
  • Can I have “git stash” to automatically include untracked files by default?
  • How do I do “git update”?
  • A Gerrit Instance that Can Rebase Projects to Google AOSP?
  • Publish Git repo on a web-only provider (no shell)
  • Installing TextBelt on my own server
  • 3 Solutions collect form web for “How to move my new branch to the latest commit in master branch?”

    You need git rebase

    #On New Branch do:
    git fetch origin master
    git rebase origin/master
    

    An alternate way is to merge master branch into new branch.

    #On New Branch do:
    git fetch origin master
    git merge origin/master
    

    Rebasing moves a branch from one commit to another. Internally, git creates new commits and applies them to the specified base (it rewrites your project history).

    git checkout C4
    git rebase master
    

    When you’ll finish working on your feature, you’ll need to merge:

    git checkout master
    git merge C4
    

    I suggest checking also the interactive rebase, using the -i parameter:

    git checkout feature
    git rebase -i master
    

    I generally like to use it to polish a feature branch before merging it into the main code base.
    You can really be sure that everything is in order before committing to the official project history. And to other eyes, they will think that you worked on your feature in a wise way. 🙂

    Git Baby is a git and github fan, let's start git clone.