Thanks to this post. It get me more understand in Git.

Let’s have a try.

1. Create a new repo on Github

Create Repo

Your first commit to master branch

1
2
3
4
5
$ git clone <your-project>
$ touch README.md
$ git add README.md
$ git commit -a -m "- initial commit"
$ git push origin master

2. Create a develop branch

1
2
3
4
5
6
7
8
9
# Branch out `develop` from `master`
$ git checkout -b develop master

# make some changes
$ echo "This is branched out from master" >> README.md
$ git commit -a -m "- initialize develop branch"

# Push to remote server and create a new branch
$ git push origin develop

Now you have 2 branches in your Github

Show 2 branches

3. Now add a new module

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Branch out `module1` from `develop`
$ git checkout -b module1 develop

# Make some changes
$ mkdir new_module
$ cd new_module
$ touch file1 file2 file3
$ cd ..

# Add & Commit
$ git add new_module
$ git commit -a -m "- added new module"

# Show all branches you have
$ git branch

# Switch to `develop`
$ git checkout develop

# Merge with branch `module1`
$ git merge --no-ff module1

# Delete `module1` branch
$ git branch -d module1

# push to remote server
$ git push origin develop

4. Everything tested fine, merge to master branch

1
2
3
4
5
6
7
8
# Switch to `master`
$ git checkout master

# Merge with branch `develop`
$ git merge --no-ff develop

# Push to remote server
$ git push origin master

If you work on only a single branch, consider a situation here:

Now you have assigned a new module, you work on the new module. Suddenly, the life copy got some bugs that need you to be fix urgently, but now you’re working on the new module which is not yet complete.

Imagine the situation above happened, it may take you a lot of time to handle this. Thus use the branching model to avoid this situation happen.

Reference: A successful Git branching model