{{announcement.body}}
{{announcement.title}}

Git Branching – Fast Forward

DZone 's Guide to

Git Branching – Fast Forward

In this article, we walk through how Git uses fast-forward for merging changes from on branch into another.

· DevOps Zone ·
Free Resource

In this article, we walk through how Git uses fast-forward for merging changes.

Think of it this way, you started watching a movie on your TV at home. You got 30 minutes into it and had to leave. While you were gone, you were able to use your phone to watch another 15 minutes from where you left off. so now you are at minute 45 in the movie.

fast-forward git example

Seems normal, right? When you got home, your TV will fast forward to minute 45 so you can resume watching as if you had been watching on the TV the whole time.

fast-forward git example

Now, apply this flow to git branches. For example, you create a branch to start work on one ticket (or solution). You finished the work on that ticket and now you want to merge it back to master.

Merging ticket back to master

In this scenario, if no additional work has occurred on master, then git can perform a Fast-Forward merge. This is where the reference for master is simply moved forward to the last commit on the branch you are merging.

Fast-forward merge in git

Fast-forward merges in git work the same way because there was no conflicting activity on master after the branch was created.

In my previous post on basic git branching, git actually performed the fast-forward merge; we just didn’t know that it happened. Find below the screenshot of the corresponding merge activity, and for reference, you read that post at https://dzone.com/articles/basic-git-branching.

  • First, switch to the target (Master) branch >> git checkout master
  • Next, merge the source branch to master using >> git merge feature1
Merging branch

So, this was a simple explanation of fast-forward merge in Git. Till next post, Happy Coding.

Topics:
devops, git, git branch, git fast-forward, tutorial

Published at DZone with permission of Jawad Hasan Shani . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}