A simple Python project for learning and practice purposes.
This application demonstrates the usage of branches.
- Filters user data from a JSON structure
- Main branch implemented a simple name filter
- Feature branch feature-filter-by-age added an age filter
- Feature branch feature-filter-by-email added an email filter
- The email filter was merged with main by a pull request
Start the project with:
python|python3 filter_users.py
This document explains the following Git history step by step:
git log --oneline --graph
* d7ed803 (HEAD -> main, origin/main) code comments added
* f05a05b Merge pull request #1 from user0815/feature-filter-by-email
|\
| * 2b3cf4e (origin/feature-filter-by-email, feature-filter-by-email) filter by email added
|/
* 435faed (origin/feature-filter-by-age, feature-filter-by-age) filter by age added
* 35d4671 basic user filter by name added
* d987b26 first commit
* d987b26 first commit
The repository is created.
This is the starting point of the entire history.
main
|
v
d987b26
first commit
* 35d4671 basic user filter by name added
* d987b26 first commit
A second commit is added directly to the main branch.
d987b26
first commit
|
v
35d4671
basic user filter by name added
At this point, the history is completely linear.
A new feature branch is created from main:
git checkout -b feature-filter-by-ageA new commit is added on this branch:
435faed filter by age added
The history now looks like this:
d987b26
first commit
|
v
35d4671
basic user filter by name added
|
v
435faed
filter by age added
Since no new commits were added to main in the meantime, this branch can later be integrated using a fast-forward merge.
The branch is merged into main:
git checkout main
git merge feature-filter-by-ageGit recognizes:
main is a direct ancestor of feature-filter-by-age
Therefore, no additional merge commit is required.
Instead, Git simply moves the main branch pointer forward.
Before fast-forward:
d987b26 --- 35d4671 main
\
435faed feature-filter-by-age
After fast-forward:
d987b26 --- 35d4671 --- 435faed
main
feature-filter-by-age
Important:
- No new commit is created.
- The history remains linear.
mainnow points to the same commit asfeature-filter-by-age.
Another feature branch is created from the current state:
git checkout -b feature-filter-by-emailA new commit is added on this branch:
2b3cf4e filter by email added
The history now looks like this:
d987b26 --- 35d4671 --- 435faed
\
2b3cf4e
feature-filter-by-email
The commit 2b3cf4e initially exists only on the feature branch.
The branch feature-filter-by-email is later merged into main using a pull request.
This creates a dedicated merge commit:
f05a05b Merge pull request #1 from user0815/feature-filter-by-email
The history now looks like this:
d987b26 --- 35d4671 --- 435faed -------- f05a05b
\ /
2b3cf4e
The merge commit f05a05b combines two development lines:
- the existing
mainhistory - the feature branch
feature-filter-by-email
Therefore, this commit has two parent commits.
The merge is displayed in git log --oneline --graph like this:
* f05a05b Merge pull request #1 from user0815/feature-filter-by-email
|\
| * 2b3cf4e filter by email added
|/
* 435faed filter by age added
Meaning of the symbols:
* Commit
| Connection line
\ Branch split
/ Merge back into main line
|\ Merge commit with two parents
After the merge, development continues directly on main.
d7ed803 code comments added
The final history becomes:
d987b26 --- 35d4671 --- 435faed -------- f05a05b --- d7ed803
\ /
2b3cf4e
HEAD, main, and origin/main now point to the latest commit:
d7ed803 (HEAD -> main, origin/main)
This means:
- The current local branch is
main HEADpoints tomain- The local
mainbranch is synchronized withorigin/main
* d7ed803 (HEAD -> main, origin/main) code comments added
* f05a05b Merge pull request #1 from user0815/feature-filter-by-email
|\
| * 2b3cf4e (origin/feature-filter-by-email, feature-filter-by-email) filter by email added
|/
* 435faed (origin/feature-filter-by-age, feature-filter-by-age) filter by age added
* 35d4671 basic user filter by name added
* d987b26 first commit
This history contains two different integration strategies.
Used for feature-filter-by-age:
main was simply moved forward.
Characteristics:
- no merge commit
- linear history
- clean and simple
- possible only if
mainhas not changed since the branch was created
Used for feature-filter-by-email:
A dedicated merge commit was created.
Characteristics:
- visible branch structure
- dedicated merge commit
- two parent commits
- common for GitHub pull requests
A fast-forward merge is simply moving the branch pointer forward.
A merge commit is a real combination of two separate development histories.