CIT-WEB-301
Software Versioning
             Department of
Computer Science and Information Systems
                 (CSIS)
                               Outline
●   Version Control Systems
●   Types of version control systems
●   Git
●   Git installation
●   Creating repositories
●   Working with local repositories
●   GitHub
●   GitHub workflows
●   Working with remote repositories
                    Unit outcomes
By the end of this lesson, you should be able to:
─ Explain the term version control system (VCS)
─ Discuss the different types of VCS
─ Install and configure git
─ Create repositories with git
─ Manage local repositories
─ Work with GitHub
─ Manage remote repositories on GitHub
  What is a Version Control System?
● A system capable of recording the changes
  made to a file or a set of files over time and
  enables the restoration of old versions.
● Why is it important?
  ─   Track file changes over time
  ─   Enable collaboration
  ─   Enables branching
  ─   Backup and restoration
  ─   Provide history of changes
                             Cont..
● In a manual system, you
  must keep changes of
  the files as different
  copies.
● To go to a previous one,
  you must restore it,
  potentially losing some
  good updates.
                             Cont..
● In a VCS you mark the
  changes made as a
  stage with a marker.
● You can easily go to the
  previous stage using the
  marker.
● No need to be manually
  saving the whole
  project.
   Types of Version Control Systems
● Local Version Control Systems
  ─ All changes are stored in a local database.
  ─ It is limited to single-user scenarios.
● Centralized Version Control Systems
  ─ Uses a single server to store all the versioned files
  ─ Clients check out files from this central place.
● Distributed Version Control Systems
  ─ Every contributor has a local copy of the entire
     project history.
                                Git
● Git is a free and open-source distributed
  version control system designed to track
  changes in computer code and other
  projects.
  ─ Initially developed to manage Linux kernel
    project
  ─ Every developer can have a copy of the project
  ─ It enables collaboration
                         Using Git
● Download Git from
  https://git-scm.com/downloads
  and install it.
● There are two versions;
  command line and GUI
● In this tutorial, the command line
  version will be used.
● Open the application, you will be
  presented with a command
  prompt.
                                  Git
● First things first, configure Git.
● Chances are high that you are going to work
  on a remote repository.
● There are three types of configurations.
  ─ System level- All users on the system and all
    their repositories.
  ─ Global level- Currently logged-in user and all
    their repositories.
  ─ Local level: A specific repository.
                      Configure git
● The following are
  some of the
  important
  configurations.
         Initialising a git Repository
● When you have created a
  project, you'll need to tell
  git that is a git repository.
● It creates a hidden folder
  called git
● You can also get a copy
  of a repository from a
  server
              The README.md file
● Is a text file typically included
  in software projects,
  websites, or repositories.
● It serves as a starting point
  for anyone encountering the
  project.
   ● Provides essential information
     and instructions.
             The README.md file
● The file can contain the following
  information
  ─ Project Overview: project description
  ─ Installation Instructions: how users
    can install the software
  ─ Usage Guide: how users can run the
    software
  ─ License Information: How others
    can use, modify, and distribute the
    code.
            Mark down elements
● Headings: supports
  several levels of headings
● Paragraph: Each line is a
  paragraph
● Bold & italicize text
  formatting.
● List: ordered and
  unordered lists.
  etc
    Recording Changes to the Repo
● Git is aware of file
  changes.
● Use the status command
  to see untracked files.
● Add the files to the
  staging area to commit
  the changes
● Save the changes using
  the commit command.
                    Ignoring files
● There could be some files and
  directories that you don’t want
  git to track.
● The .gitignore file is used to
  tell Git which files or
  directories to ignore in a
  project.
● Create the file and include the
  list of files & dirs to ignore
                          GitHub
● GitHub is a web-based
  platform that uses Git for
  version control.
● Other features are specific to
  GitHub and not Git
  ─ Pull request
  ─ Repository forking
  ─ Issue tracking
                GitHub- workflows
● Centralized workflow
  ─ There is a centralized repo
  ─ Team members clone the repo and work on it
  ─ Team members push & updates to the repo
● Integration manager
  ─ One member has push access to the repo
  ─ Contributors folk and clone the repo.
  ─ Contributors make pull request to the manager
  ─ The manager pulls and pushes the updates (if
     happy)
                       Using GitHub
● Create an account, its free.
● Create a repository
  ─ Specify the name
  ─ Description
  ─ Visibility
  ─ Readme file (optional)
  ─ .gitignore file (optional)
  ─ License (optional)
       Remote – Local connection
● Create a local repository
  ● Use “git init”
● Use git remote add
  origin command to
  connect the local repo to
  the remote repo.
● Set personal access
  tokens (GitHub does not
  accept passwords)
                           Git log
● Allows you to view the
  history of commits in a
  repository.
● Provides a detailed
  information such as
  commit IDs, author names,
  commit messages, and
  dates.
                     Git restore
● The command can be
  used to restore
  files/directories from
  previous commits.
● It can also be used to
  restore remove files from
  the staging area.
                    Git checkout
● This command switches
  your working directory to
  the state at a particular
  commit.
● It results into “HEAD
  detached state”- you're not
  on any branch.
● Create a branch from
  there or go to any branch.
                      Git branch
● The git branch
  command is used to
  manage branches in a
  Git repository.
● Branches allow you to
  work on different
  versions of your project
  simultaneously.
                      Git branch
● The git branch
  command is used to
  manage branches in a
  Git repository.
● Branches allow you to
  work on different
  versions of your project
  simultaneously.
                       Git stash
● The git stash command is
  used to temporarily save
  changes that you've made
  in your working directory.
● It enables going into
  another branch, comeback
  later and restore the
  untracked & uncommitted
  changes.
                        Git merge
● The git merge command is used
  to integrate changes from one
  branch into another.
● The merge process:
  ─ Ensure your working directory is
    clean
  ─ Switch to the target branch
  ─ Merge the source branch into the
    target branch
           Git merge- Strategies
● Fast-Forward
  Merge- moves the
  pointer of the
  target branch
  forward to the
  latest commit in
  the source
  branch.
            Git merge- Strategies
● Three-Way
  Merge-This involves
  creating a new merge
  commit that has two
  parent commits: one
  from the target branch
  and one from the
  source branch.
         Handling Merge Conflicts
● Conflicts occur when changes in the
  source branch and the target branch
  overlap.
● When this happens, Git will stop and
  allow you to resolve the conflicts
  manually.
  ─ Make different changes to the same line
  ─ One person edits a file and another
    person deletes
         Handling Merge Conflicts
● Conflicts occur when changes in the
  source branch and the target branch
  overlap.
● When this happens, Git will stop and
  allow you to resolve the conflicts
  manually.
  ─ Make different changes to the same line
  ─ One person edits a file and another
    person deletes
               Handling Merge Conflicts
● The process is as follows:
  ─ Start the merge
  ─ Git identifies conflicts
  ─ Resolve conflicts
  ─ Add the resolved files
  ─ Commit the merge
o   Fix options
    ─   Accept current change
    ─   Accept incoming change
    ─   Accept both
    ─   etc.
               Undoing commits
● You can undo a merge
  after the merge was done
  and committed or before
  commit.
● If its before commit use
  the –abort argument
● If its after the merge use
  git reset option.