Git fast-forward merge strategy 😎
Tags: git, todayilearned
Published: 2019-12-29 02:03:37

# Jeez wait, but what would that be? Is it to eat? 
![](https://media3.giphy.com/media/pPhyAv5t9V8djyRFJH/giphy.gif?cid=790b76118b25292fab3ad6d0590fc48d725697761f4aba3c&rid=giphy.gif)
Fast-foward is possible when there are no conflicts between the branches involved and when the development branch is ahead of the main branch.

# Our scenario 
When we follow Git Flow correctly, there is a rule that we call the "Golden Rule of Rebirth." Basically, this rule says that recovery should not be used in public agencies either, as it has high catastrophic and destructive potential or commission history, whenever there is disagreement between local agencies and remote agencies. However, there is a very nice workflow that can be used by combining both commands.

Let's imagine that you need to start working on a task within a Git-controlled project. If you follow Git Flow correctly, you will need to create a branch so that you can work on your task


You will probably generate a new branch to develop your task from master. We can then have the command below:

```bash
git checkout –b feature #creating the branch of work
```
Then we can generate our commits, saving our work gradually while other people can mix their commits with the master.

![](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTcOhmCw05tIQ3_RmxoQyTPrZteIYgSlcJ-COThZTSj_9UG2gtc&s)


Now is the time to integrate our commits with the master. We need to do this in two ways, basically:
* Bring the changes that were later entered into the master into our branch. We need this step to ensure that subsequent changes will not "break" the changes we made to our branch;
* Bring changes from our branch to the master, updating it with our work and making it available to other developers.

Let's deal with the first step at this time. If we stop to analyze the situation, it makes more sense to bring the master commits to feature in a “transparent” manner, ie without the need for an additional commit. 

This will keep our history completely linear and will ensure that new master commits will be applied to our branch at the “right time”, preserving the order in which they were generated. So for this first step, the rebase makes a lot more sense. Therefore, assuming we are already in the feature branch, we can execute the command below:
```bash
git rebase master
```


This will produce the following illustration:

![](https://seesparkbox.com/foundry/uploads/article_uploads/after-rebasing.png)

The first step has been completed! We have our feature branch properly synchronized. 

However, our master branch, which is the main branch, is still outdated as it does not have our commits yet. We need to pull our commits from the feature branch to the master branch. As we are talking about the main branch, it is important to maintain the traceability of the code management process, making it clear even when local branch commits were pulled into the master branch.

So for this second stage, merge is much more interesting than rebase.
In this situation, all possible problems of “blending” the two branches (such as conflicts) were resolved during the rebase process. 

In this second step, we can simply change the pointer of our master branch, pointing it to the last commit of our feature branch. When this process happens, we call this fast-foward merge strategy. Fast-foward is possible when there are no conflicts between the branches involved and when the development branch is ahead of the main branch. 

From the previous illustration, this is exactly the situation.

```
git checkout master # going to the master branch
git merge feature    # merge between master and feature
```

Therefore, our master branch is now as follows:
![](https://i.stack.imgur.com/x7z9z.png)
Note that this way we have the best of both worlds: we don't have the commit history polluted by secondary commits in the feature branch (thanks to rebase) and we have the traceability of when the master branch was modified by an integration (because of merge).


for today that's it

![](https://media1.giphy.com/media/8mkykXIicXOVms2xYE/giphy.gif?cid=790b7611736c6e0a819d3d1e1d497f20b1aea6db7c0fffd8&rid=giphy.gif)