GIT - According to Syllabus
GIT - According to Syllabus
Version Control Systems (VCS) are essential tools in software development and project management, allowing
multiple contributors to work together on a project while keeping track of changes, avoiding conflicts, and maintaining
a detailed history of modifications.
Version Control
Version control is the practice of tracking changes to files (code, documents, etc.) in a systematic way. It helps in
managing multiple versions of a file, keeping a detailed history of who made changes, what changes were made, and
when.
https://orion021.github.io/krishnan_t/ 1 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
• Collaboration: Developers can work independently on different parts of the project and merge changes
without overwriting each other's work.
• Backup and Recovery: Since every change is saved, it's easy to recover previous versions or undo mistakes.
• Tracking Project History: Detailed logs of changes (commits) are stored, providing insights into what changed,
why, and by whom, making it easier to track the evolution of a project.
• Code Conflict Resolution: When multiple people work on the same files, version control helps merge their
changes, minimizing conflicts and reducing the risk of lost work.
• Branching and Experimentation: Developers can create isolated branches for new features or experiments,
keeping the main project stable until changes are ready to be merged.
Git: A distributed version control system, Git is the most widely used VCS due to its flexibility, speed, and support
for branching and merging. It allows each developer to have a local repository with the full project history.
SVN (Subversion): A centralized version control system, SVN stores all changes on a central server. It’s still used in
some organizations but lacks the flexibility and offline capabilities of Git.
Mercurial: Similar to Git in its distributed model, Mercurial is known for being simple and user-friendly but is less
widely adopted.
Installing Git
• Windows:
2. Run the installer and follow the prompts, accepting the default settings for most users. You’ll also be
prompted to install Git Bash, which provides a command-line interface for executing Git commands.
• macOS:
Make sure you have homebrew installed in the Mac Device. To install Git using Homebrew by run the
following command in the Terminal:
• Linux:
Most Linux distributions come with Git available in their package managers. Use the following command
based on your distribution:
https://orion021.github.io/krishnan_t/ 2 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
After installing Git, to verify whether GIT installed or not execute the below command in Terminal or bash window.
This will display the version of git we have installed
git --version
It’s essential to configure it with your user information. To do that execute commands in the terminal:
Initializing Repositories
Git manages project versions through repositories. To create a new repository, follow these steps:
1. Navigate to Your Project Directory: Open your terminal and change to your project folder using the cd
command. For example:
cd path/to/your/project
git init
This command creates a hidden .git directory within your project folder. This directory contains all the metadata
and history for your project.
3. Checking the Repository Status: After initializing, you can check the status of your repository using:
git status
This command shows the current state of the repository, indicating any untracked or modified files. If you see
"No commits yet," it means you haven't added any files to your repository yet.
4. Understanding the .git Directory: The .git directory is crucial for Git's functionality. It contains:
o Objects: Store the actual data (blobs for file content, trees for directories).
https://orion021.github.io/krishnan_t/ 3 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Cloning Repositories
Cloning is the process of creating a local copy of a remote repository. This is useful when you want to contribute
to an existing project or access its files.
1. Find the Repository URL: Go to the repository page on GitHub and locate the HTTPS or SSH URL.
This command creates a directory named after the repository and copies all files and the entire history into it.
3. Navigate into the Cloned Directory: Once cloned, change into the newly created directory:
cd repository
This command displays the commit history, including commit hashes, authors, dates, and messages. So whenever
it is needed to see the history of the repository use any of the above commands.
After modifying files or creating new ones, you need to stage them before committing. Staging files prepares them
for a commit.
1. Stage Individual Files: To add a specific file to the staging area, use:
git add filename
2. Stage All Changes: To stage all modified and new files, use:
3. Check Staged Files: This command what is the current status of repository you cloned to local directory(folder).
git status
Committing Changes
Committing saves your changes to the local repository with a descriptive message.
1. Create a Commit: After staging your files, create a commit with a message describing the changes:
2. Amending a Commit: If you need to modify the last commit (e.g., to add missed changes), use:
git commit --amend
This opens an editor to modify the commit message or include additional changes staged before running the
command.
https://orion021.github.io/krishnan_t/ 4 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Getting Help: Git includes a robust help system. You can access help for any command with:
Git stores configuration settings at three different levels, allowing developers to customize Git's behaviour on a
global, system, or repository-specific level. Understanding and managing these configuration files is key to optimizing
your workflow.
Basically, all the user credentials are stored within the .gitconfig file in the user folder.
o System-Level Configuration (/etc/gitconfig): Settings that affect all users on a machine. Requires
superuser privileges to modify.
o Global-Level Configuration (~/.gitconfig or ~/.config/git/config): Settings that apply to the user across all
repositories. This is the most commonly modified config file.
o Local-Level Configuration (<repo>/.git/config): Settings that only apply to a specific Git repository. Local
settings override global ones.
o You can view or edit these configuration files manually or through the Git command-line interface. To view
or modify your global configuration, you can run:
o This opens the global configuration file in your default text editor, where you can add or change settings.
Once if changes made close the file everything will be saved.
https://orion021.github.io/krishnan_t/ 5 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Git's branching and merging allow developers to work independently on features, bug fixes, or experiments
without affecting the main project. This ensures changes can be developed, tested, and reviewed before being merged
into the main codebase.
Managing Branches
A branch in Git represents an independent line of development. The default branch created when you initialize a
repository is typically called main (or master in older Git versions). Branches allow you to isolate work, making it easier to
test and develop new features or fixes without impacting the main code.
Key Concepts:
Creating a Branch: To create a new branch, you use git branch <branch-name>. For example, to create a branch
called feature-xyz, you'd run:
Listing and Viewing Branches: To see a list of all branches in your repository, use:
git branch
• The current branch you are working on will have an asterisk (*) next to it.
Switching Between Branches: To move between branches, use the git checkout or git switch commands:
Deleting Branches: Once you are done with all the work , you can delete it:
This deletes the branch locally (if it's fully merged with another branch). To force-delete an unmerged branch, use
https://orion021.github.io/krishnan_t/ 6 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
2. Managing Repositories
A remote repository is hosted on platforms like GitHub, GitLab, or Bitbucket. It allows multiple developers
to collaborate by pushing and pulling changes.
Example:
You can view the list of remote repositories associated with your project using:
git remote -v
This will display the fetch and push URLs for each remote.
Collaboration in Git revolves around syncing changes between local and remote repositories. The most
common Git commands used for collaboration are push, pull, and fetch.
git push (Uploading Changes to the Remote Repository) : After making changes locally, you can upload your
changes to the remote repository using git push.
Example:
git push origin main
This pushes your commits in the main branch to the origin remote (e.g., GitHub).
git pull (Downloading and Merging Changes from the Remote): To download changes from the remote repository
and merge them into your local branch, use git pull:
Example:
git pull origin main
This fetches the latest changes from the remote origin and merges them into your local main branch.
git fetch (Downloading Changes without Merging): git fetch only downloads changes from the remote repository
but does not automatically merge them into your working branch. You can inspect the changes first and merge
them manually if needed.
Example:
After fetching, you can view the new changes (commits) and decide whether to merge them.
https://orion021.github.io/krishnan_t/ 7 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Once if all the work is done in the branches we created, we can combine it to the main or master branch.
In order merge one branch to another we can use the below command,
Based on the current status of repository git will perform Fast-Forward Merges or Three-Way Merge.
Types of Branching:
Fast-Forward Merges:
Example:
• You create a new branch, make some changes, and then merge it back to the main branch.
• If no one else has changed the main branch, Git can "fast-forward" the main branch to include your changes
without creating extra commits.
Three-Way Merges:
• This type of merge happens when both your branch and the main branch have new changes since you
branched off.
• Git compares three versions of the code: your branch, the main branch, and the point where both branches
started (the common ancestor).
• It combines the changes from both branches into one new commit, called a merge commit
Example:
• You and your friend both make changes in different branches.
• When you try to merge your branch back into the main branch, Git creates a new merge commit to combine
the changes from both of you.
Merge Conflicts:
• Conflicts occur when Git cannot automatically combine changes from two branches because the same file or
line was changed in incompatible ways in both branches.
• Git will mark the conflict and stop the merge process. You’ll need to resolve the conflicts manually by editing
the files and then committing the resolution.
https://orion021.github.io/krishnan_t/ 8 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
4. Git Workflows
1. Centralized Workflow
In the Centralized Workflow, a single central repository serves as the authority where all developers commit
their changes. It mimics the workflow used by older version control systems like SVN, where there is only one main
branch, often called the main or master branch, and all developers work directly on this branch.
How it Works:
• Once changes are ready, they push them directly to the central repository.
• There's no branching involved unless absolutely necessary, and all changes are committed directly to the main
branch.
Advantages: Disadvantages:
• Simple and easy to understand. • Hard to scale for large teams. Lacks flexibility for
feature isolation
• Ideal for small teams or single-developer
projects. • Higher risk of conflicts since all changes are
directly on the same branch.
In this workflow, each new feature or bug fix is developed in its own isolated branch. Once the feature is
complete, the branch is merged back into the main branch (often the main or develop branch).
How it Works:
• Developers create a new branch for each feature (git checkout -b feature-branch).
• Once the feature is complete, it is merged into the main branch using a pull request or a direct merge.
Advantages: Disadvantages:
• Isolates work, reducing the risk of conflicts. • Requires more branch management.
• Encourages clean and organized commit • Continuous testing and integration are needed
histories. to ensure compatibility of different branches
when merged.
• Suitable for teams working on multiple features
simultaneously.
https://orion021.github.io/krishnan_t/ 9 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
3. Gitflow Workflow
Gitflow is a structured branching model introduced by Vincent Driessen. It is designed for projects with
scheduled releases and a defined structure for how work progresses through different stages.
How it Works:
• The repository has two long-lived branches: main (or master) for production-ready code and develop for ongoing
development.
• Once features are complete, they are merged back into develop.
• When preparing for a release, a release branch is created from develop to prepare the code for production.
• Once the release is stable, it is merged into both main and develop.
• For urgent fixes, a hotfix branch is created from main and merged back into both main and develop after the fix.
Advantages: Disadvantages:
• Provides a structured and clear release process. • Can be complex for small teams or projects with
• Isolates different stages of development, making continuous delivery.
it easier to manage production releases and
• Requires careful branch management to avoid
ongoing development.
confusion.
4. Forking Workflow
Popular in open-source projects, where external contributors do not have direct access to the main repository.
Instead, they fork the repository, make changes in their copy, and submit a pull request to merge their changes.
How it Works:
• A developer forks the original repository, creating a personal copy under their account.
• Once changes are complete, they push them to their fork and create a pull request to the original repository.
• Project maintainers review and merge pull requests into the main project.
Advantages: Disadvantages:
• Maintains strict control over the main repository. • Higher overhead for maintainers to review and
merge pull requests.
• Ideal for large-scale, open-source projects where
multiple contributors are involved. • Contributors need to keep their forks in sync with
the original repository.
https://orion021.github.io/krishnan_t/ 10 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Git is a version control system that uses a distributed architecture. Instead of maintaining centralized records of
changes, each developer has a local repository with a full history of the project, which is achieved through Git's internal
object model. The core of Git's version control is based on objects that are stored in a repository.
Each object in Git is immutable—once created, it cannot be changed. This ensures data integrity and ensures
that all changes are recorded transparently, with no risk of overwriting previous versions.
All of these objects are stored in the .git/objects directory of your repository, where each object is stored as
a file named according to the first two characters of the hash, followed by the remaining 38 characters.
Git is fundamentally a content-addressable filesystem where every piece of data is stored as an object. These
objects are immutable and uniquely identified by a SHA-1 hash.
• A SHA-1 hash is a 40-character hexadecimal string derived from the content of an object.
• Even a single change in the object (e.g., adding a space in a file) will generate an entirely new hash.
Example:
https://orion021.github.io/krishnan_t/ 11 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Git objects are the basic data structure for everything in the Git system. There are four types of objects called
Blob, Tree, Commit and Tag.
The Blob (Binary Large Object) represents the contents of a file in Git. It is the raw data of the file, without any file
name or directory structure. Git does not track metadata such as the filename or the directory of a file in a Blob—only
the file's content.
How it Works:
o When you add a file to Git using git add, Git stores the file's content as a Blob object in the .git/objects
directory.
o The content of the Blob object is hashed using the SHA-1 algorithm to generate a unique identifier for the
object. The object is saved as a file in the .git/objects directory. If a file hasn't changed, Git will reuse
the existing Blob object to save space.
Example:
Hello, World!
o Git will create a Blob object, hashing the file's contents to generate a SHA-1 identifier (e.g., 7f8d4a4b76...),
and store it in the .git/objects/7f/8d4a4b76... file.
A Tree object in Git represents a directory structure. It acts like a "container" that groups files (Blobs) and other
subdirectories (Trees) together. Each Tree object stores the names and permissions of the files it contains, along with
the hashes of the Blobs and Trees it points to.
How it Works:
o A Tree object points to one or more Blobs (for files) or other Trees (for subdirectories).
o The structure of the directory is maintained by referencing all files and directories under that directory.
If you commit your project, Git creates a Tree object to represent the state of the project at that point.
my_project/
├── hello.txt
└── src/
└── main.py
o The root directory my_project/ is represented by a Tree object. This Tree contains:
o The src/ directory itself will be represented by another Tree object, which will point to the main.py file (a
Blob object).
https://orion021.github.io/krishnan_t/ 12 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
A Commit object in Git represents a snapshot of your entire project at a specific point in time. It records the state of
the project by referencing a Tree object (which represents the directory structure), along with metadata such as the
commit message, author, timestamp, and parent commits.
How it Works:
o Each commit contains a reference to a single Tree object, which is essentially the state of the repository
at the time of the commit.
o Git also records the author's information (name, email) and the commit message.
o Commits are linked to each other via parent commits, forming a linked list of changes (a commit
history). Every commit stores a pointer to its parent, and the root commit has no parent.
Example: Let's say you made a commit with the message "Initial commit". Git will create a Commit object that
contains:
o The Tree object representing the structure of your project at that point.
A Tag object is used to label a specific commit, often to mark a significant milestone, like a version release (e.g.,
v1.0, v2.0). There are two types of tags:
o Annotated Tag: A full object that includes the tagger's name, email, date, and an optional message, and
can be signed.
How it Works:
o Tags are pointers to a specific commit. While tags don't change over time, they provide a meaningful
label to refer to specific commits.
o Annotated tags are recommended as they include metadata and can be signed with a GPG key for
security and verification.
Example: You want to mark a version release, say v1.0. You would create an annotated tag:
https://orion021.github.io/krishnan_t/ 13 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Git's storage system is optimized for efficiency and performance. It uses a combination of loose objects and
packfiles to manage the storage of Git objects.
a. Loose Objects
Loose objects are individual Git objects (Blobs, Trees, Commits, Tags) stored as separate files in the .git/objects
directory. Each object is stored as a file named using the first two characters of its SHA-1 hash followed by the remaining
38 characters.
b. Packfiles
Packfiles are a mechanism used by Git to compress and store multiple objects together to save space and improve
performance. When a repository grows large, Git automatically packs objects into packfiles, which can store thousands
of objects in a single file.
o To save disk space and optimize performance by reducing redundant copies of the same object.
Git provides several powerful commands to help you recover from common problems.
git reset is used to move the current branch pointer to a specific commit.
o Soft Reset (--soft): Moves the branch pointer but keeps changes in the staging area.
o Mixed Reset (--mixed): Moves the branch pointer and unstages changes.
o Hard Reset (--hard): Resets the branch pointer and discards all changes in the working directory and
staging area.
Example: To undo the last commit and keep changes in the working directory:
git revert creates a new commit that undoes the changes of a previous commit. Unlike reset, which rewrites history,
revert preserves the commit history and is safe to use on shared branches.
https://orion021.github.io/krishnan_t/ 14 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Git Stashing is a useful feature for temporarily saving your uncommitted changes in your working directory and
staging area. This is particularly helpful when you need to switch branches or perform other tasks without committing
the changes. Here's how to use Git Stash in a series of steps:
Stashing Changes
To stash your current changes (both staged and unstaged), use the following command:
git stash
• Restores the working directory to the state of the last commit, so you can work on something else.
You can also add a message to describe the stash for later reference:
git stash save "Message describing the stash"
Viewing Stashes
After stashing changes, you might want to see the list of all stashes you've made. To list all stashes:
git stash list
This will show a list of stashes, with the most recent one listed first, like below:
This applies the changes from the most recent stash to your working directory but does not remove it from the
stash list.
https://orion021.github.io/krishnan_t/ 15 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Once you've applied the stash and are happy with the changes, you might want to remove it from the stash list.
To do that, use:
Alternatively, if you want to apply and remove the most recent stash in one step, use:
This will apply the most recent stash and remove it from the list.
For more detailed information (showing the actual diff), add the -p or --patch flag:
If you no longer need any stashes and want to remove them all, use:
Git hooks are scripts that Git executes before or after certain Git commands (such as commit, push, merge, etc.).
These hooks allow you to automate various tasks like running tests, formatting code, or enforcing project standards,
making Git a powerful tool for automating workflows in your development process.
Git hooks are located in the .git/hooks/ directory of your Git repository. By default, the .git/hooks/
directory contains sample scripts with .sample extensions, which you can modify or replace to suit your needs.
pre-commit:
Common use: Running linters, checking for formatting errors, or running tests before committing.
commit-msg:
Triggered after the commit message is entered but before the commit is finalized.
Common use: Validating commit message format (e.g., ensuring a specific style or structure).
post-commit:
Common use: Sending notifications or running tasks like documentation updates after a commit.
https://orion021.github.io/krishnan_t/ 16 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
pre-push:
Common use: Running tests or checks to ensure the code is ready to be pushed.
post-push:
Common use: Deploying changes or updating CI/CD pipelines after a successful push.
post-merge:
Common use: Cleaning up merge artifacts or notifying teams after a successful merge.
Writing clear, concise, and informative commit messages is essential for maintaining a clean and understandable
project history. A good commit message makes it easier for team members (and your future self) to understand what
changes were made and why.
o It should describe what the commit does, not how it’s done.
Example:
2. Body (Optional):
o Explain why the change was made and provide additional context if needed.
o Mention any relevant details such as bug numbers, related issues, or tests.
Example:
https://orion021.github.io/krishnan_t/ 17 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Continuous Integration (CI) is a software development practice that encourages frequent integration of code
changes into a shared repository. Rather than waiting for large batches of changes to be merged, developers integrate
their code multiple times a day. This approach ensures that problems are detected early, and allows for faster and
smoother collaboration.
Automated Testing: Each integration is automatically tested to ensure that the new code doesn't break the
existing functionality.
Early Detection: By frequently committing changes, teams can spot and resolve integration issues earlier.
Faster Code Delivery: CI ensures that code is always in a deployable state, enabling faster delivery and frequent
releases.
Continuous Deployment (CD) extends CI by automating the release process. In a CD pipeline, code that passes CI
checks (such as tests and validation) is automatically deployed to staging or production environments. This allows for
rapid and consistent deployment without manual intervention.
Faster Releases: Every change that passes testing is deployed, meaning production updates happen frequently.
Reduced Manual Errors: By automating deployment, CD eliminates human error during the release process.
Consistent Deployment: Automation ensures that every environment (e.g., dev, staging, production) gets the
same deployment process, leading to fewer environment-specific issues.
https://orion021.github.io/krishnan_t/ 18 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
• Code Commit: A developer commits changes to a version control system (e.g., GitHub).
• CI Process: Code is fetched, compiled, and tested (automated testing, linting, etc.).
• CD Process: If the code passes all tests, it's automatically deployed to a testing/staging environment, and
potentially to production.
This process ensures that software can be deployed in a rapid, reliable, and repeatable way, which is crucial in
modern DevOps practices.
GitHub Actions is an integrated automation tool that allows you to define workflows directly within GitHub
repositories. These workflows are composed of jobs that execute a sequence of steps. These jobs can automate tasks
like building, testing, and deploying your code to various environments.
o Workflows: Defined in YAML files (located in .github/workflows/). Workflows are triggered by events
(e.g., a push to the repository, a pull request, or a scheduled event).
o Jobs: Each workflow contains one or more jobs. A job is a collection of steps that run on a specific
runner (virtual machine or container).
o Steps: Each step in a job performs a single action, such as checking out code, installing dependencies, or
running tests.
o Runners: Runners are servers that execute the jobs. GitHub provides hosted runners with predefined
environments, but you can also create custom, self-hosted runners if you need more control over the
environment.
Triggers: A workflow is initiated by a trigger, such as a push to a branch or a pull_request event. For example:
on:
push:
branches:
- main
https://orion021.github.io/krishnan_t/ 19 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Job Execution: Jobs within a workflow can run in parallel or sequentially. Each job can contain multiple steps.
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Run tests
run: npm test
Runners: The job is executed on a runner, which GitHub provides or you can host yourself. Common runners
include ubuntu-latest, windows-latest, and macos-latest.
Example Workflow:
on:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
3. Setting Up CI Pipelines
To set up a CI pipeline in GitHub Actions, you need to define a .yml configuration file in the .github/workflows
directory. This file specifies how the pipeline behaves—when it runs, what steps it takes, and what jobs are involved.
Step-by-Step Breakdown:
o This file should be placed in the .github/workflows/ directory of your GitHub repository.
https://orion021.github.io/krishnan_t/ 20 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
o Triggers: Set the trigger events for the workflow. Common triggers include push, pull_request, and
schedule.
o Example:
on:
push:
branches:
- main
pull_request:
branches:
- main
3. Define Jobs:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Node.js dependencies
run: npm install
- name: Run Tests
run: npm test
o You can define conditions to control whether a job or step runs based on certain criteria.
o Example: Only deploy if tests pass:
jobs:
deploy:
if: success() # Deploy only if the previous jobs were successful
runs-on: ubuntu-latest
steps:
- name: Deploy to server
run: ./deploy.sh
https://orion021.github.io/krishnan_t/ 21 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
4. Deployment Strategies
Once the CI pipeline has successfully run, the next step is to deploy the code. This process can be automated as
part of your CD pipeline. Deploying automatically ensures that the latest stable version of your code is always running in
your environment.
o After running tests in the CI pipeline, you can add a deployment job that pushes the code to a staging or
production server.
2. Environment-Specific Deployment:
o You may have different environments, such as development, staging, and production.
o You can create separate jobs for each environment and conditionally deploy based on branch names or
tags.
o You can implement rollback strategies if something goes wrong during deployment. For example, you
might revert to a previous version of the code in case of failure.
Once your CI/CD pipeline is set up, it is crucial to monitor its execution and ensure that it is performing as
expected.
Monitoring Tools:
• GitHub Actions Dashboard: This provides an overview of all workflows and their statuses. You can view logs for
each job and each step, making it easy to debug any failures.
• Logs: Every job and step generates logs, which you can access from the GitHub Actions interface. These logs
show detailed information on what went wrong and where the process failed.
• Status Badges: You can add status badges to your project’s README file to show whether the pipeline passes or
fails.
Notifications:
• You can integrate Slack or email notifications to alert your team about the status of a workflow. For example,
you can configure GitHub Actions to send a message to a Slack channel when a build or deployment fails or
succeeds.
https://orion021.github.io/krishnan_t/ 22 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Benefits of CI/CD
• Improved Code Quality: Automated testing on every code change means potential bugs are identified and fixed
before they make it into the main branch. This regular checking helps keep code stable and high-quality.
• Faster Releases: Automating the build, test, and release process speeds up the entire pipeline, allowing teams to
quickly get new features, bug fixes, and updates to users.
• Enhanced Collaboration: By pushing small, frequent updates, developers avoid “merge hell” and maintain
smooth workflows. Developers see the latest code changes from each other almost immediately, reducing
conflicts.
• Reduced Risks: Small updates are easier to test, monitor, and roll back if needed. Releasing updates in smaller,
manageable chunks means there’s less chance of something going wrong.
CI/CD Tools
• Jenkins: An open-source automation server, highly customizable with plugins for different languages, tools, and
stages in the CI/CD pipeline. Jenkins can be integrated into various stages of the pipeline, from code integration
to deployment.
• GitLab CI/CD: Built into GitLab repositories, it allows developers to define pipelines within their GitLab projects.
This is great for projects already on GitLab because everything can be configured in one place.
• CircleCI: Known for seamless integration with GitHub, CircleCI runs CI/CD processes in the cloud, enabling fast
builds and supporting parallel executions.
• GitHub Actions: GitHub’s native CI/CD tool allows defining workflows directly in the repository, integrating well
with other GitHub features like issues and pull requests. It’s ideal for projects already hosted on GitHub.
o Blue-Green Deployment:
▪ There are two identical versions of the production environment, named “blue” and “green.”
Users are directed to one (say, blue), while the other (green) is updated.
▪ Once the update is ready, the traffic is switched to the green environment. If anything goes
wrong, the switch can revert to the blue environment, minimizing downtime.
o Canary Releases:
▪ A new version is initially released to a small subset of users to monitor for issues. If everything
works well, it’s then gradually rolled out to more users.
▪ This strategy helps identify any unforeseen problems with real user feedback in a controlled way.
o Rolling Deployments:
▪ This approach gradually replaces instances of the old version with the new one. This method
minimizes downtime because only a few instances are replaced at a time, keeping most of the
service running.
o Feature Toggles:
▪ Feature toggles (or feature flags) allow developers to hide incomplete or experimental features
from users. Features are deployed in a disabled state and can be turned on gradually when
they’re ready.
https://orion021.github.io/krishnan_t/ 23 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
o Netflix: Netflix has a sophisticated CI/CD system that allows them to deploy new updates to users multiple
times a day. They use canary releases to test changes on a small scale before releasing them widely.
o Amazon: Amazon deploys thousands of updates daily across its platforms. They use a CI/CD approach that
emphasizes automated testing, rollback capabilities, and monitoring.
o Automate Everything: Automated testing, building, and deployment reduce the risk of human error and
speed up the pipeline. Aim to automate every stage of the pipeline.
o Build Once, Deploy Everywhere: Once code is built and packaged, reuse that same build in all environments
(testing, staging, production) to avoid inconsistencies.
o Test Continuously: Implement unit tests, integration tests, and possibly UI tests at each stage to ensure code
quality and functionality.
o Monitor and Set Alerts: After deploying to production, use monitoring tools to track performance, usage,
and errors. Alerts can notify the team if there’s an issue, helping to catch problems quickly.
o Regularly Review Pipelines: Keep the pipeline efficient by removing unused steps, updating dependencies,
and optimizing processes. This helps maintain fast, reliable releases.
https://orion021.github.io/krishnan_t/ 24 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
GitHub/GitLab Mastery
Github:
GitHub is a cloud-based platform designed for developers to collaborate on software projects, host(store) source
code, and manage version control using Git. GitHub provides a user-friendly interface and a variety of tools to facilitate
collaborative development, making it one of the most popular platforms for open-source and private projects.
GitHub Features:
Repositories:
Repositories are storage spaces for projects, containing files, commit history,
branches, and configuration files.
Key Features:
Types of Repositories:
Public Repositories: Open to the public and ideal for open-source projects.
Private Repositories: Restricted access; only authorized users can view or contribute.
Special Files:
LICENSE: Defines the legal permissions and restrictions for repository usage.
Issues:
• Use Markdown to format issue descriptions with headers, lists, and code snippets.
• Reference commits or pull requests using # (e.g., #42 references issue/pull request 42).
https://orion021.github.io/krishnan_t/ 25 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Mechanism for proposing and reviewing changes before merging into the main branch.
Workflow:
• Open a pull request from the feature branch to the main branch.
Enhancements:
• Enable branch protection rules to enforce mandatory reviews or CI checks before merging.
Forks:
Use Cases:
https://orion021.github.io/krishnan_t/ 26 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Branches:
Best Practices:
GitHub Pages:
Setup:
Use Cases:
https://orion021.github.io/krishnan_t/ 27 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Managing Teams:
Collaborators:
Permission Levels:
GitHub Organizations:
Features:
Teams:
Features:
• Create nested teams for granular roles (e.g., frontend and backend teams).
GitHub Actions:
Use Cases:
Workflow Anatomy:
Events:
https://orion021.github.io/krishnan_t/ 28 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Jobs:
Steps:
name: Node.js CI
on:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
Secrets in Actions:
• Store sensitive information (e.g., API keys) in the repository or organization settings.
GitHub Packages:
Publishing:
Accessing Packages:
o Install packages using package managers like npm install or docker pull.
Private Packages:
https://orion021.github.io/krishnan_t/ 29 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
GitHub Documentation:
README:
Best Practices:
GitHub Wiki:
Features:
Markdown’s - https://www.markdownguide.org/basic-syntax/
https://orion021.github.io/krishnan_t/ 30 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
Which GitHub feature allows users to assign tasks and track progress?
Issues
https://orion021.github.io/krishnan_t/ 31 | 😁 👻 ✌️ 😎
GIT – Version Control Made Simple Collaboration Made Powerful
What does the term "workflow" refer to in the context of GitHub Actions?
A series of automated steps to perform tasks like building, testing, and deploying code
Which of the following GitHub features helps teams organize their work?
Issues and Projects
What is a common method for tracking changes and contributions in an open-source project?
Using pull requests to propose changes
Which GitHub feature helps ensure code contributions meet specific standards?
Required Reviews.
How can sensitive data like API keys be securely managed in GitHub/GitLab CI/CD pipelines?
By storing them in environment variables or secrets.
https://orion021.github.io/krishnan_t/ 32 | 😁 👻 ✌️ 😎