Professional Documents
Culture Documents
Mohsen Mabrouki
2020-2021
2
ABOUT GIT
• Created by Linus Torvalds, creator of
Linux, in 2005
– Came out of Linux development
community
– Designed to do version control on
Linux kernel
• Goals of Git:
– Speed
– Support for non-linear development
(thousands of parallel branches)
– Fully distributed
– Able to handle large projects
efficiently
3
BRANCHES IN GIT
A branch represents an independent line of development.
The core idea behind the Feature Branch Workflow is that all feature
development should take place in a dedicated branch instead of
the master branch. This encapsulation makes it easy for multiple
developers to work on a particular feature without disturbing the
main codebase. It also means the master branch will never contain
broken code, which is a huge advantage for continuous integration
environments.
7
REBASING BRANCHES
Rebasing is the process of moving or combining a sequence of commits to a
new base commit. Rebasing is most useful and easily visualized in the context
of a feature branching workflow. The general process can be visualized as the
following:
9
GITFLOW WORKFLOW
Gitflow Workflow is a Git workflow design that was first published and made
popular by Vincent Driessen at nvie. The Gitflow Workflow defines a strict
branching model designed around the project release. This provides a
robust framework for managing larger projects.
This workflow doesn’t add any new concepts or commands beyond what’s
required for the Feature Branch Workflow. Instead, it assigns very specific
roles to different branches and defines how and when they should interact.
10
USING GIT
USING GIT-FLOW
FEATURE BRANCHES
Each new feature should
reside in its own branch,
which can be pushed to the
central repository for
backup/collaboration. But,
instead of branching off
of master, feature branches
use develop as their parent
branch. When a feature is
complete, it gets merged back
into develop. Features should
never interact directly
with master.
14
CREATING A FEATURE
BRANCH
Without the git-flow extensions:
git checkout develop
git checkout -b feature_branch
FINISHING A FEATURE
BRANCH
When you’re done with the development work on the feature, the
next step is to merge the feature_branch into develop.
Without the git-flow extensions:
git checkout develop
git merge feature_branch
RELEASE BRANCHES
RELEASE BRANCHES
CREATING A RELEASE
BRANCH
Making release branches is another straightforward branching
operation. Like feature branches, release branches are based on
the develop branch. A new release branch can be created using the
following methods.
Without the git-flow extensions:
git checkout develop
git checkout -b release/0.1.0
FINISHING A RELEASE
BRANCH
Once the release is ready to ship, it will get merged it
into master and develop, then the release branch will be deleted. It’s
important to merge back into develop because critical updates may have
been added to the release branch and they need to be accessible to new
features.
To finish a release branch
Without the git-flow extensions:
git checkout master
git merge release/0.1.0
Or with the git-flow extension:
git flow release finish '0.1.0'
20
HOTFIX BRANCHES
Maintenance
or “hotfix” branches are used
to quickly patch production
releases.
Hotfix branches are a lot
like release branches
and feature branches except
they're based
on master instead of develop.
This is the only branch that
should fork directly off
of master.
21
CREATING A HOTFIX
BRANCH
Without the git-flow extensions:
FINISHING A HOTFIX
BRANCH
Similar to finishing a release branch, a hotfix branch gets
merged into both master and develop.
git checkout master
git merge hotfix_branch
git checkout develop
git merge hotfix_branch
git branch -D hotfix_branch
SCENARIO
We are going to star by creating a directory.
mkdir project
cd project
Then, we initialize the directory as a git directory.
git inti
Before we start commiting code to git, we need to identify
ourselves to git, so when we commit a change of the code,
we can later track who did what
git config –-global user.name "flan"
git config –-global user.email "flan@faltan.com
29
SCENARIO
SCENARIO
Now that we have a project and git is aware of it, we can begin creating
our branches and start modifying our code.
We are going to use git flow commands to create and finish
our branches.
As shown in previous slides, the first branch that we need to create is
the develop branch, and when we use git flow inti command the
develop branch will be created automatically, the output of the
following command will be some questions about the naming
conventions for you branches, it's recommended to use the default
values.
git flow init
31
SCENARIO
So far, we initialized our git directory, which should create a master
branch for us, then we run the git flow inti command which created a
develop branch, now we can start adding features to our code, but
before that, we need to create a feature branch
git flow feature start myfeature
In this part feel free to modify your software project (whatever it is you
want to do), and once you've done with that, we need to merge our
new cool features to the develop branch,
git add .
git commit –m "added a feature"
git flow feature finish myfeature
SCENARIO
Our develop branch now have the latest feature, what we need to do
now, is to create a release branch, that contain the new feature that we
added, to do that we use the following command.
git flow release start myrelease
Let's say that we tested our release, and we are happy with the results
and we want to merge it with the master branch, all we have to do is to
run the command below.
git add .
git commit –m "finished a release"
git flow release finish myrelease
This command will perform the following actions for us
• Merge 'myrelease' into the 'master' branch
• Tags the release with its name
• Back-merge 'myrelease' into 'develop' branch
• Remove the release branch 'myrelease'
33
SCENARIO
Let's imagine that the release we just merged into master, isn't working
the way it supposed to, and we need to fix it, we can't go through the
whole process again to fix a miner issue, as we discussed in earlier
slides, we create a hotfix branch from the master branch, to quickly fix
these issue.
To create a hotfix branch with git-flow tool, just run the command
below
git flow hotfix start myrelease
We need to add our release name, in our case it is 'myrelease'
Let's say we fixed the issue, and we are ready to merge back our newly
fixed code into master, all we have to do is to run the following
command.
git add .
git commit –m "added a feature"
git flow hotfix finish myrelease
34
SCENARIO
Now if we'd like to work with a remot server like github gitlab etc …
First, we need to create a remot repo in GitHub or anyother VCS server
Then add the remot server in GIT like below
git remote add origin "link of the server repo"
Our remote repository is now added to git we can simply push any
branch that we are working on using this command
git push origin master
Or
git push origin develop
We can also use git flow command to push our braches
To push feature brach use this command
git flow feature publish myfeature
To push feature branch use this command
git flow release publish myrelease
35
TO CONCLUD
Here we discussed the Gitflow Workflow. Gitflow is one of many styles of Git
workflows you and your team can utilize.