You are on page 1of 28

Git

Today‘s Lesson Agenda

MaibornWolff Git TBD vs GitFlow


Introduction

Version Control Exercise


System
Today‘s Lesson Agenda

MaibornWolff Git TBD vs GitFlow


Introduction

Version Control Exercise


System
Today‘s Lesson Agenda

MaibornWolff Git TBD vs GitFlow


Introduction

Version Control Exercise


System
>VCS

Definition

VCS is a software tool that helps to manage and


track the changes for a set of files over the time in
an automate way. Moreover, it allows the team to
work on the same project simultaneously and to
return to any previous version if needed.
>VCS

Types

Centralized Version Control System (CVCS)

> Central repository

> Network dependency

> Lock-modify-unlock model

> Complex branching & merging

> Examples: SVN, Perforce, …


Benefits

Advantages Disadvantages
Easy to learn and manage. Needs to connect to the network to
perform operations.
More control over users and their access. Risk of losing all data if the central server
gets crashes.
Can’t collaborate at all when the central
server is down.
For every command, CVCS connects the
central server which impacts speed of
operation
>VCS

Types

Distributed Version Control System (DVCS)

> Every developer has a clone of the repository as well


as its history

> Any changes made to the source code can be tracked


by others.

> Offline work

> Developers share changes by “pushing” and “pulling”

> Merging changes is often automatic

> Examples: Mercurial, …


Benefits

Advantages Disadvantages
Can work offline, unless we need to use Initial checkout of a repository is slow.
central repository for push and pull.
Faster than CVCS & Better performance.
Merging and branching is easy
(sometime there is no need to do it
manually).
Code is safe even the central server is
crashed.
Today‘s Lesson Agenda

MaibornWolff Git TBD vs GitFlow


Introduction

Version Control Exercise


System
>GIT

Definition

Git is an open-source version control system which keeps track


on any change in the source code and make it possible for
multiple persons to work on the same task or different ones at
the same time. Moreover, it can handle both small and large
project efficiently where it also support non-linear development
though branching features. Also, it’s categorized as a DVCS.

DVCS
> G I T

Features

Free and open source.

Distributed development & Supports non-linear


development.

Branching is easier

Extensible

Tracks history
> G I T

Workflow

First step in Git Workflow is cloning the project to


obtain a working copy of the codebase or what
we can call a snapshot of the project. Later we can
modify the working copy by updating our
codebase form the central server or by our own
change with editing, adding or moving files, the
team uses status and diff operations to review
changes to ensure accuracy and functionality.
Once that is done, they commit changes creating
a version in Git's history. This cycle repeats as they
continuously review changes incorporating
feedback from colleagues.
>GIT

Workflow
We can divide the Git Workflow into 4 states:
§ Working Directory: The workspace where we
update/create/delete our files.
§ Staging Area (Index): Intermediate place between the
working directory and local repo. It’s used to stage
which files we want to track & commit.
§ Local repository: the local version of the repository. All
the commits come here first.
§ Remote repository: Remote server which hosts our
repository and to/from which we push/pull our
changes.
Commit Branch
commit is recording changes of Branch is similar to “parallel
set of files. In this operation, we universe” so it basically creating a
> G I T create a snapshot for the current new line of development which we
state of the project. usually create when we want to
For each commit we have: work on a new feature and
Key words Snapshot. merged it back with the master
Unique Identifier. branch which is by default the
Commit message. main.
Author and Timestamp.

Pull Push
Pull is the operation of copying all Push is the opposite operation of
the changes from a remote pull so it is copying all the
repository instance on our central changes from our local repository
server to a local one. to the remote one.
>GIT

Commands

Configurations Initializing Project Commits


Ø git config --global user.name "Your Ø git init: This will initializes a new Git Ø git add: Selects specific files or
Name”: To set the global username repository in the current directory changes to include in the next
for commits. and create a hidden .git folder commit.
Ø git config user.name: Displays the where all version control data will Ø git commit: Creates a new commit
user name that is currently set up. be stored. with the staged changes.
Ø git config --global user.email Ø git cherry-pick: Picks a commit
"your@example.com": To set our Cloning from a branch and apply to
global email address. Ø git clone: To copy a remote another one.
Ø git config user.email: Displays the repository to your local machine.
user email that is currently set up.
Ø git config --list: Lists all the global
configuration settings.
>GIT

Commands

Sync Repositories Review Conflicts


Ø git pull: Fetches and merges Ø git status: Displays the status of our Ø git merge: Merges changes from
changes from a remote repository working directory, staged changes one branch into another.
into our local branch. and untracked files. Ø git rebase: Applies commits
Ø git push: pushes our commits from Ø git log: Displays a chronological list sequentially from one branch into
our local commits to a remote of commits, showing commit another one after the last commit,
repository. messages, authors and resulting in a more linear and
Branching timestamps. organized commit history.
Ø git branch: Displays all existing Ø git diff: Displays the differences Ø git rebase -i: rebase in interactive
branches or creates a new branch. between our changes and the last mode this mean git open UI to
commit. display commits that will be
Ø git checkout : Switches to a copied and then we can reorder
different branch. Ø git show: Displays the changes
introduced by a specific commit. them and specify what commit we
want to pick or omit.
Ø git blame: Shows who last modified
each line of a file and when.
>GIT

Commands

Reverting Bonus
Ø git reset: Resets the repository to a Ø git it config --global
previous commit, removing all the alias.<shortcut> <command>:
commits and the changes after it. Creates our own aliases for
Ø git revert: Creates a new commit commands.
that undoes the changes from Ø git stash: Stores our changes
reverted commit. temporarily to avoid committing
them.
Ø git commit --amend -m "New
commit message": Changes the
last commit message.
Ø git commit --amend: Include
staged changes to the previous
commit.
>Git

Rebase vs Merge
Aspect Merge Rebase
History Preserves the original Adjust the history to
commit history. adapt to linear history.
Resulting One commit at the end Move all commits after
commits that have 2 parents. last commit of other
branch.
Conflicts Solve them once. Solve them with each
commit.
When to • Preserving Branch • Maintain a clean
use History. History.
• Shared Branch. • Solo Dev.
• Less Conflict • Feature Branch
Resolution. cleanup ( Re-order or
squash)
• Integration testing.
>Git

Best Practices

Clear commit Utilize branches to isolate


messages that different features & bug Regularly push your changes
describe the purpose fixes with descriptive to remote repositories.
FEATURE TEAM

of the changes. names

Java Developer ML Engineer DevOps Engineer

Make smaller, frequent Regularly merge from the


Create a .gitignore file to
commits where Each main into your feature
specify files or patterns that
commit should make a Tech Lead branches (Rebase
should be ignored by Git.
single, focused change. instead of Merge). Data Scientist Cloud Architect
Today‘s Lesson Agenda

MaibornWolff Git TBD vs GitFlow


Introduction

Version Control Exercise


System
Git

Let’s try it out!

Task 1:

• Create directory

• Initialize a git repo in this directory


Git

Let’s try it out!

Task 2:

• Create file, modify it


• Check repo status
• Stage file
• Commit, make it meaningful
Git

Let’s try it out!

Task 3:

• Create two files, modify them


• Stage and commit
• View commit history
Git

Let’s try it out!

Task 4:

• Create new branch & switch to it


• Make changes to one of the files
• Commit
Git

Let’s try it out!

Task 5:

• Switch back to main branch


• Check changed file contents
• Merge branch to the main branch
Thanks for your
attention

people. code. commitment.

You might also like