Skip to main content

· 5 min read

compare gitflow and github flow

Gitflow

Gitflow is a branching model built around Git, defining a structured approach to managing branches for different purposes in larger projects. It consists of several key branches: master, develop, feature, release, and hotfix.

More information: Gitflow Workflow | Atlassian Git Tutorial

img

Pros

  • Structured branching model for managing larger projects.
  • Well-defined release process with versioning.
  • Clear separation of features, releases, and hotfixes.

Cons

  • Complexity, especially for smaller projects or teams.
  • Potential for longer release cycles.
  • Overhead in managing multiple branches.

GitHub Flow

GitHub Flow, in contrast, is a simpler workflow emphasizing continuous delivery and frequent deployments. It revolves around a single main branch (main or production) and feature branches.

More information: GitHub flow - GitHub Docs

img

Pros

  • Simplicity in its approach, suitable for smaller, agile teams.
  • Continuous deployment and quick iterations.
  • Flexibility for rapid feature development.

Cons

  • Might struggle with managing larger release cycles or complex projects.
  • Lack of a formal release process might cause confusion in some scenarios.
  • Limited in handling more structured release management needs.

Comparative Analysis

Suitability

  • Gitflow: Suited for larger projects with well-defined release cycles and structured development phases.
  • GitHub Flow: Ideal for smaller teams requiring rapid iterations and continuous deployment without complex branching.

Ease of Use

  • Gitflow: More complex due to multiple long-lived branches.
  • GitHub Flow: Simpler, with fewer branches and a straightforward process.

Adaptability

  • Gitflow: Less flexible due to its structured nature, but effective for projects following a more traditional release model.
  • GitHub Flow: Highly adaptable for agile teams and projects requiring frequent releases.

Recommendations

  • For larger projects with clear release cycles and a need for structured development phases, consider adopting Gitflow.
  • For smaller, agile teams focusing on rapid iterations and continuous deployment, GitHub Flow might be more suitable.

Demo

Gitflow Workflow Demo

Setting Up Gitflow

Assuming you have Git installed, to initialize Gitflow in a repository:

  1. Install Gitflow via command line:
brew install git-flow
# Using apt-get (Ubuntu)
sudo apt-get install git-flow
# Using Homebrew (Mac)
  1. Initialize Gitflow in a Git repository:
git flow init

Using Gitflow

  1. Feature Development:
  • Start a new feature:

    git flow feature start new-feature
  • Develop your feature on this branch, committing changes as needed.

  1. Feature Completion:
  • Finish the feature branch:

    git flow feature finish new-feature
  1. Release Process:
  • Start a release:

    git flow release start 1.0.0
  • Perform release-specific tasks, bug fixes, version updates.

  • Finish the release:

    git flow release finish 1.0.0
  1. Hotfixes:
  • Start a hotfix:

    git flow hotfix start issue-123-fix
  • Make necessary changes and finish the hotfix:

    git flow hotfix finish issue-123-fix

GitHub Flow Demo

GitHub Flow is simpler and follows a more straightforward branching model:

  1. Main Branch (Production):
  • All work is directly committed to the main branch.
  1. Feature Development:
  • Create a feature branch:

    git checkout -b feature-branch main
  • Develop the feature on this branch, committing changes.

  1. Pull Request:
  • Once feature development is complete, open a pull request (PR) on GitHub.
  • Review and discuss changes with colleagues in the PR.
  • Merge the feature branch into the main branch upon approval.
  1. Continuous Deployment:
  • Changes merged into the main branch trigger automated deployments or continuous integration/continuous deployment (CI/CD) processes.

Summary

GitflowGitHub Flow
DescriptionStructured branching model for larger projectsSimpler workflow for rapid iterations and continuous deployment
Key Branchesmaster, develop, feature, release, hotfixmain (or production), feature branches
ProsStructured for larger projectsSimplicity for smaller, agile teams
Well-defined release processContinuous deployment and quick iterations
Clear separation of features, releases, and hotfixesFlexibility for rapid feature development
ConsComplexity, especially for smaller projects or teamsStruggle with larger release cycles or complex projects
Potential for longer release cyclesLack of a formal release process may cause confusion
Overhead in managing multiple branchesLimited in handling structured release management needs
SuitabilitySuited for larger projects with structured cyclesIdeal for smaller teams without complex branching
Ease of UseMore complex due to multiple long-lived branchesSimpler with fewer branches and straightforward process
AdaptabilityLess flexible due to structured natureHighly adaptable for agile teams and frequent releases

Both Gitflow and GitHub Flow offer distinct advantages depending on the project's size, complexity, and release needs. The choice between the two workflows should align with the team's working style, project requirements, and desired release management strategy.

· 2 min read

Images

docker images                   # List all images
docker pull <image_name> # Pull an image from Docker Hub
docker build -t <image_name> . # Build an image from the current directory
docker rmi <image_id> # Remove an image

Containers

docker ps                       # List running containers
docker ps -a # List all containers
docker run <image_name> # Create and start a container
docker exec -it <container_id> bash # Access a running container's shell
docker stop <container_id> # Stop a running container
docker rm <container_id> # Remove a container

Volumes

docker volume ls                # List all volumes
docker volume create <volume_name> # Create a volume
docker run -v <volume_name>:/path/in/container <image_name> # Mount a volume to a container

Networks

docker network ls               # List all networks
docker network create <network_name> # Create a network
docker run --network=<network_name> <image_name> # Connect a container to a network

Compose

docker-compose up               # Start services defined in a docker-compose.yml
docker-compose down # Stop and remove services defined in a docker-compose.yml

Registry

docker login                    # Log in to a Docker registry
docker push <image_name> # Push an image to a registry
docker pull <registry>/<image_name> # Pull an image from a registry

System

docker info                     # Display system-wide information
docker version # Show the Docker version
docker system prune # Remove all stopped containers, unused networks, and dangling images

Dockerize Applications

docker build -t <image_name> .         # Build a Docker image
docker run -p <host_port>:<container_port> <image_name> # Run a Docker container

· 2 min read

Git Basics

git init
git clone <repository_url>
git status

Staging and Commits

git add <file(s)>
git commit -m "Commit message"
git reset --soft HEAD^ // Undo Last Commit (Keep Changes)
git reset --hard HEAD^ // Undo Last Commit (Discard Changes)

Branching

git branch <branch_name>
git checkout <branch_name>
git checkout -b <branch_name>
git merge <branch_name>
git branch -d <branch_name>

Remote Repositories

git remote add <remote_name> <repository_url>
git push <remote_name> <branch_name>
git pull <remote_name> <branch_name>

Logging and History

git log
git show <commit_hash>
git diff

Miscellaneous

touch .gitignore  // Ignore Files (Create .gitignore)
git checkout -- <file(s)> // Undo Changes in Working Directory
git reset HEAD <file(s)> // Undo Staged Changes

Cherry-pick

git cherry-pick <commit_hash>

Rebase

git rebase <base_branch>
git rebase -i <base_branch> // Interactive rebase

Squash Commits during Rebase

// Change "pick" to "squash" for the commits you want to squash
// Follow on-screen instructions to edit the commit messages
git rebase -i <base_branch>

Amend the Last Commit

git commit --amend

Stash Changes

git stash
git stash save "Stash message"

Apply Stashed Changes

git stash apply
git stash pop // Apply and remove from stash

View Stash List

git stash list

Show Differences with Stash

git stash show -p <stash_id>

Discard Stashed Changes

git stash drop <stash_id>
git stash clear // Remove all stashes

Tagging

git tag <tag_name>  // Create lightweight tag
git tag -a <tag_name> -m "Tag message" // Create annotated tag
git push origin <tag_name> // Push tag to remote

Submodules

git submodule add <repository_url> <path>  // Add submodule
git submodule update --init --recursive // Initialize submodules
git submodule foreach git pull origin master // Update submodules

Git Configurations

git config --global user.name "Your Name"
git config --global user.email "your@email.com"

Show Configurations

git config --list

· 2 min read
  1. c# basic(datatype, exception, ...) -> important
  2. Algorithm (bubble sort, selected sort, ...) -> quick view
  3. OOP (4 ) -> important
  4. SOLID (5) -> quick view
  5. C# advance (delegate, generic, async ) -> optional
  6. SQL(join(8), understand func vs store procedure) -> important
  7. Linq -> quick view
  8. ef core -> quick view
  9. webapi -> optional

Create and Build Projects

dotnet new console -n MyConsoleApp    // Create a new console application
dotnet new webapi -n MyWebApi // Create a new Web API project
dotnet build // Build the project

Run Applications

dotnet run                            // Run the application
dotnet run --project <project_path> // Run a specific project
dotnet watch run // Run with file watching

Add Dependencies

dotnet add package <package_name>     // Add a NuGet package
dotnet restore // Restore dependencies

Generate Code

dotnet new classlib -n MyLibrary      // Create a class library
dotnet add reference <project_path> // Add a project reference
dotnet publish -c Release // Publish the application

Unit Testing

dotnet new xunit -n MyTests           // Create xUnit test project
dotnet test // Run tests

Entity Framework Core

dotnet ef migrations add <migration_name>    // Add a migration
dotnet ef database update // Apply migrations

Publish and Deploy

dotnet publish -c Release --self-contained // Publish a self-contained application

Package Management

dotnet nuget push -k <api_key> -s <source> <package.nupkg>    // Publish a NuGet package

ASP.NET Core Identity

dotnet new identity -n MyIdentityApp   // Create an ASP.NET Core Identity project

Azure Functions

dotnet new func -n MyFunction          // Create an Azure Functions project

Clean Up

dotnet clean                          // Clean the build output

· 6 min read

SQL Clauses

  • WHERE, ORDER BY, GROUP BY, and HAVING: Crafting strategic queries.
  • Today's exploration: INNER JOIN, OUTER JOIN, EXCLUDING JOIN, SELF JOIN, CROSS JOIN, UNION, and UNION ALL.

Why Do We Need JOIN?

  • Combining data from multiple tables based on matching conditions for comprehensive analysis.

INNER JOIN: A Deeper Dive

-- Example of INNER JOIN
SELECT c.CustomerID, c.FullName, o.FoodName
FROM Customer c
INNER JOIN CustomerOrder o ON c.CustomerID = o.CustomerID;

In this practice, we retrieve customer information along with their corresponding orders using INNER JOIN.

JOIN More Than 2 Tables

-- Example of INNER JOIN with 3 tables
SELECT c.CustomerID, c.FullName, o.FoodName, d.FullAddress
FROM Customer c
INNER JOIN CustomerOrder o ON c.CustomerID = o.CustomerID
INNER JOIN DeliveryAddress d ON d.ID = o.DeliveryAddressID;

Extending the concept of INNER JOIN to involve three tables for a more comprehensive result set.

LEFT JOIN: Embracing Incompleteness

-- Example of LEFT JOIN
SELECT c.CustomerID, c.FullName, o.FoodName
FROM Customer c
LEFT JOIN CustomerOrder o ON c.CustomerID = o.CustomerID;

Incorporating LEFT JOIN to include all customers, even those without orders.

RIGHT JOIN: Balancing the Equation

-- Example of RIGHT JOIN
SELECT c.CustomerID, c.FullName, o.FoodName
FROM Customer c
RIGHT JOIN CustomerOrder o ON c.CustomerID = o.CustomerID;

Implementing RIGHT JOIN to include all orders, even those without customers.

FULL JOIN: Embracing Completeness

-- Example of FULL JOIN
SELECT c.CustomerID, c.FullName, o.FoodName
FROM Customer c
FULL JOIN CustomerOrder o ON c.CustomerID = o.CustomerID;

Utilizing FULL JOIN to encompass all customers and orders, regardless of matches.

LEFT EXCLUDING JOIN: Seeking the Unique

-- Example of LEFT EXCLUDING JOIN
SELECT c.CustomerID, c.FullName, o.FoodName
FROM Customer c
LEFT JOIN CustomerOrder o ON c.CustomerID = o.CustomerID
WHERE o.CustomerID IS NULL;

Applying LEFT EXCLUDING JOIN to identify customers without orders.

RIGHT EXCLUDING JOIN: Excluding to the Right

-- Example of RIGHT EXCLUDING JOIN
SELECT c.CustomerID, c.FullName, o.FoodName
FROM Customer c
RIGHT JOIN CustomerOrder o ON c.CustomerID = o.CustomerID
WHERE c.CustomerID IS NULL;

Implementing RIGHT EXCLUDING JOIN to identify orders without customers.

OUTER EXCLUDING JOIN: Excluding in Unison

-- Example of OUTER EXCLUDING JOIN
SELECT c.CustomerID, c.FullName, o.FoodName
FROM Customer c
FULL JOIN CustomerOrder o ON c.CustomerID = o.CustomerID
WHERE c.CustomerID IS NULL OR o.CustomerID IS NULL;

Integrating OUTER EXCLUDING JOIN to identify unmatched records from both tables.

SELF JOIN: Connecting Within

-- Example of SELF JOIN
SELECT emp.ID, emp.FullName, manager.FullName AS Manager
FROM Employee emp
INNER JOIN Employee manager ON emp.ManagerID = manager.ID;

Demonstrating the concept of SELF JOIN to connect records within the same table.

CROSS JOIN: Expanding Horizons

-- Example of CROSS JOIN
SELECT *
FROM A
CROSS JOIN B;

Expanding horizons with CROSS JOIN to combine each row from one table with each row from another.

UNION: Merging Similarities

-- Example of UNION
SELECT FromColumnTableA FROM A
UNION
SELECT FromColumnTableB FROM B;

Merging similarities with UNION to combine result-sets from two tables.

UNION ALL: Embracing All

-- Example of UNION ALL
SELECT FromColumnTableA FROM A
UNION ALL
SELECT FromColumnTableB FROM B;

Embracing all with UNION ALL, including duplicates in the result set.

Sub Queries and Advanced Operators

  • Exploring the power of subqueries.
  • Advanced operators: EXISTS, ALL, IN, ANY.

What We Will Explore Today?

  • Sub queries, advanced operators, rules of subqueries, and practical exercises.

Subquery Basics

  • A sub-query, or inner query, nested inside a larger query.
  • Works independently within the outer query.
  • Execution sequence: Inner query executes first, results stored, and outer query runs on stored results.
  • Exception: Correlated subqueries reference outer query columns.

Example 1: Subquery for Average

-- Example of Subquery
USE LECTURE4_FUNCTION
SELECT LastName, Physic, (SELECT AVG(Physic * 1.0) FROM Student) AS 'AVG OF Physic'
FROM Student;

Example 2: Subquery in WHERE Clause

-- Example of Subquery in WHERE
USE LECTURE5_JOIN_DEMO
SELECT CustomerID, FullName
FROM Customer
WHERE CustomerID IN (SELECT CustomerID FROM CustomerOrder);

Types of Subqueries

  • Single-row subquery.
  • Multiple-row subquery.
  • Multiple-column subquery.
  • Correlated subquery.
  • Nested subquery.

Single-Row Subquery

-- Example of Single-Row Subquery
USE LECTURE5_JOIN_DEMO;
SELECT CustomerID, FullName
FROM Customer
WHERE CustomerID = (SELECT CustomerID
FROM CustomerOrder
WHERE FoodName = 'Heo Quay');

Exercise: Single-Row Subquery

Query CustomerID, OrderID, FoodName from CustomerOrder with Delivery FullAddress = 'TP. HCM' using a single-row subquery.

Multiple-Row Subquery

-- Example of Multiple-Row Subquery
USE LECTURE5_JOIN_DEMO
SELECT CustomerID, FullName
FROM Customer
WHERE CustomerID IN (SELECT CustomerID FROM CustomerOrder);

Exercise: Multiple-Row Subquery

Query CustomerID, OrderID, FoodName from CustomerOrder with Delivery FullAddress = 'TP. HCM' or 'TP. HA NOI' using a multiple-row subquery.

Multiple-Column Subquery

-- Example of Multiple-Column Subquery
USE LECTURE5_JOIN_DEMO;
SELECT CustomerID, FullName
FROM Customer
WHERE EXISTS
(SELECT CustomerID, OrderID, FoodName
FROM CustomerOrder
WHERE CustomerOrder.CustomerID = Customer.CustomerID);

Exercise: Multiple-Column Subquery

Create a database, perform a self-join on the Employee table, and query managers with at least 1 employee.

Correlated Subquery

  • Normal subquery executes first and provides a value to the outer query.
  • Correlated subquery references a column in the outer query and executes the subquery once for each row in the outer query.
-- Example of Correlated Subquery
USE LECTURE5_JOIN_DEMO;
SELECT CustomerID, FullName
FROM Customer
WHERE EXISTS
(SELECT CustomerID, OrderID, FoodName
FROM CustomerOrder
WHERE CustomerOrder.CustomerID = Customer.CustomerID);

Exercise: Correlated Subquery

Create a database, perform a self-join on the Employee table, and query managers with at least 1 employee.

Nested Subquery

-- Example of Nested Subquery
USE LECTURE5_JOIN_DEMO;
SELECT CustomerID, FullName
FROM Customer
WHERE CustomerID IN (SELECT CustomerID
FROM CustomerOrder
WHERE DeliveryAddressID = (SELECT ID
FROM DeliveryAddress
WHERE FullAddress = 'TP. HA NOI'));

Rules of Subqueries

  • Enclose a subquery in parentheses.
  • Must include a SELECT clause and a FROM clause.
  • Subqueries that return more than one row can only be used with multiple-value operators.
  • Can include WHERE, GROUP BY, and HAVING clauses.
  • Can include an ORDER BY clause only with a TOP clause.
  • Can nest subqueries up to 32 levels.

Advanced Operators: EXISTS

  • Used to test for the existence of any record in a subquery.
-- Example of EXISTS
USE LECTURE5_JOIN_DEMO;
SELECT CustomerID, FullName
FROM Customer
WHERE EXISTS
(SELECT CustomerID, OrderID, FoodName
FROM CustomerOrder
WHERE CustomerOrder.CustomerID = Customer.CustomerID);

Advanced Operators: ALL

  • Returns TRUE if ALL of the subquery values meet the condition.
-- Example of ALL
USE LECTURE5_JOIN_DEMO;
SELECT CustomerID, FullName
FROM Customer
WHERE CustomerID = ALL (SELECT CustomerID FROM CustomerOrder);

Advanced Operators: IN

  • Allows specifying multiple values in a WHERE clause.
-- Example of IN
USE LECTURE5_JOIN_DEMO;
SELECT CustomerID, FullName
FROM Customer
WHERE CustomerID IN (SELECT CustomerID FROM CustomerOrder);

Advanced Operators: ANY

  • Allows performing a comparison between a single column value and a range of other values.
-- Example of ANY
USE LECTURE5_JOIN_DEMO;
SELECT CustomerID, FullName
FROM Customer
WHERE CustomerID = ANY (SELECT CustomerID FROM CustomerOrder);