Gitflow 101: A Memo on Development Workflow with GitHub
Published: 2022-03-04 18:50:04

This is my memo after I completely crushed the main branch and re-learned how I could avoid this disaster(the story is [here](https://medium.com/@lada496/force-merge-in-git-796a1cb997e8)). I hope I can save others from getting same problem as us.

## Gitflow

According to [the document by Bitbucket](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow), Gitfolw is “an abstract idea of a Git workflow”.

There are mainly three types of branches: main, develop, and features.

![an image of git flow](https://cdn-images-1.medium.com/max/2000/1*oY32izMaEBooViR1k_1WsQ.png)

The following is the typical usage of their branches.

### main

The branch for storing the official history.

### develop

The branch for integration of features.

### features

Each feature should have their own branch whose parent branch is develop. Features branches are normally named an individual name to identify what feature the branch adds whereas main and develop are always main and develop.

## How to push each feature to the develop branch

I would like to show the basic process of pushing a feature branch to the develop branch. The chart below is the overview of the process.

![](https://cdn-images-1.medium.com/max/2000/1*H4dyKoDdicPUX-2rNX9VHQ.png)

### Patten1: No develop branch updates

### 1. Switch to develop branch

After adding all files and committing the latest change to your feature branch, move to the develop branch.

    git switch(or checkout) develop

You can check your current working branch by the command below.

    git branch

You are in hello-world branch in this example.

![](https://cdn-images-1.medium.com/max/2468/1*rUq6h-VERdyVJ11bzuD1Ig.png)

### 2. Pull latest develop repo from GitHub repo

Pull latest develop repo just for checking if there are any updates or not.

    git pull origin develop

If you see the message below, there are no update on develop branch.

![](https://cdn-images-1.medium.com/max/2000/1*dFFrq5WYAuoFWEyGotJCDw.png)

### 3. Push your branch to GitHub repo

    // go back your feature branch
    git switch(or checkout) your-feature

    // push
    git push --set-upstream origin hello-world

### tip

If it is the first time for your branch to push to GitHub, you can get the command by typing the command below.

    git push

Then you will get this message and you can copy the given command.

![](https://cdn-images-1.medium.com/max/2280/1*BfNufGUsaMlWfXccWkKkmQ.png)

### 4. open a pull request

Go to the GitHub repository page and click “Compare & pull request”.

![](https://cdn-images-1.medium.com/max/3616/1*KdHYjkEc9EpZLYNwxm3vTQ.png)

CHANGE THE DESTINATION TO DEVELOP!!!
This is super important because the default destination is the main though the appropriate destination in this case is the develop.

![](https://cdn-images-1.medium.com/max/4896/1*V-xgPk_R7kW1Y68jPhVTiw.png)

It seems a good convention to use these blue square areas. (I found an [example](https://github.com/react-bootstrap/react-bootstrap/pull/6234) from an open source project)

![](https://cdn-images-1.medium.com/max/4944/1*ufQufvDB5rJNeiicJ2FExw.png)

You will see this screen and done:)

![](https://cdn-images-1.medium.com/max/3628/1*hrwdDy1ceIAGQG0C7C70nA.png)

### Patten2: There are updates on develop branch

1 and 2 procedures is almost same as Pattern1.

### 1. Switch to develop branch

After adding all files and committing the latest change to your feature branch, move to the develop branch.

    git switch(or checkout) develop

### 2. Pull latest develop repo from GitHub repo

Pull latest develop repo just for checking if there are any updates or not.

    git pull origin develop

If you find there are some updates, you have to merge these changes before you push your feature branch.

![](https://cdn-images-1.medium.com/max/2436/1*Pme09q3HuSugQ5iKHye_xg.png)

### 3. back to your feature branch

    git switch(or checkout) your-feature-branch

### 4. merge your local develop branch

    git merge develop

If you see this message, it’s time to deal with merge conflict. Sometimes you might have to make sure what changes to keep by asking your project leader.

![](https://cdn-images-1.medium.com/max/2200/1*wMTCzDZZJs1m8OSkclWiUw.png)

### 5. Manage the conflict

If you use VS code, you can choose an option and click it.

![](https://cdn-images-1.medium.com/max/2812/1*bYiXxuuVIjMwIu0qUc64sw.png)

In this case, I chose “Accept Both Changes”.

![](https://cdn-images-1.medium.com/max/2564/1*I9hgsRU64yFCQPZdoTYw4A.png)

Then, commit these changes and push it. The process on the GitHub page is the same as Pattern1.

That’s it! Thanks for reading :)

The original article is [here](https://towardsdev.com/github-we-are-save-main-repository-committee-ad12961aa50a)