Git Training: Introduction to Git — Distributed Version Control System

Deepak Khanna
3 min readDec 14, 2020

Why version control system or SVN?

  • Allows to store more than 1 version of the code base
  • Working with same code at different places at the same time
  • TFS is centralized version control system
  • Centralized & Distributed VCS
  • CENTRALIZED
  • Repository will be stored in centralized DB
  • Entire repository is stored in a central machine
  • Accessing A repository from multiple workspaces and to be connected to 1 machine which maintains and manages the commit, changes, history at 1 place
  • Disadvantage: you need separate server and local repo setup
  • DISTRIBUTED
  • Ever user will have its own local repo
  • Ever user will have its own workspace
  • While syncing with other users you need to PULL / FETCH
  • This user need to be necessary to connected to central machine.
  • Code to be written ono local repo and as per desire push / pull / fetch for sharing code with different users working in the team
  • Git and GitHub is different !
  • Git is version control system, no centralized machine required
  • GitHub as Hosted VCS, it is a provider for Git.
  • It has hosting platform for VCS
  • No local sever required
  • Private / Public repos
  • Public repos are FREE and are exposed to general public, anyone having absolute URL can access the Repo. Ideal for open source projects
  • To access Private repos you need to have GitHub subscription. It comes with a paid subscription with minimum $9/month. Only team / collaborators can access. Ideal for closed source projects (not sharing code with external parties)
  • Know about the Security standards that GitHub holds
  • Goto GitHUb.com search for VS Code, use node.js framework called Electron install the VS Code and build your version of VS Code IDE
  • Common terms:
  • Repository
  • Can be Public / Private
  • Every repo will default branch as “master”, it gets created every time to create new repo
  • Repo represents owner, team, collaborators, source code
  • GitHub User
  • Branch
  • A parallel version of the repository
  • Allows to work freely without disturbing original
  • Ever repo has a “master” branch
  • Branches can be created from existing branches
  • Collaborator
  • With read and write access to repo, able to pull and push code
  • Not a owner but invited by Owner
  • Additionally Holds permissions of a collaborator
  • Contributor
  • Not an owner or collaborator
  • Contributes to projects by accepting pull requests and merging
  • Clone
  • Copy of repository in local system
  • Git clone command to clone repo
  • Commit
  • Like check-in in TFS environment
  • Fork
  • Remote to Remote
  • Creating copy from other repository, writing your wrapper around it and release your own project separately
  • Mostly used in open source projects
  • Push
  • Merge changes of local repo to remote
  • Requires authentication for both public and private repos
  • Anonymous access is not allowed
  • Pull
  • To sync local with remote repo
  • Fetch and merge
  • Pull-Request
  • Notifying Collaborators to review and merge the Code to the DEV branch or any other branch
  • Fetch
  • Merge
  • Git checkout master (branch)
  • Git checkout <<branch name>>
  • Git merge develop (branch)
  • Before pushing code to repository GIT runs algorithm knows your CI and notifies if there is conflict in the code which being pushed
  • Managing / storing versions
  • Restore previous version
  • Backup
  • Track changes
  • Helps to identify What changes happened to your code or your code is going through since it has been written and released to the server

Working with Repositories

  • Learn to Sign up and create public repository
  • Git clone <<remote repository URL>>
  • Git clone add <<file name>>
  • Git commit <<file name>> (this commits to local repository)
  • Git push (to push local changes to remote repository), it will ask for username and password
  • Stage and unstage commit from Visual Studio code version control
  • Git commit -a -m
  • Git status
  • Git fetch (fetches the data) + git merge (to merge in local repo)
  • Working directory and actual committed directory are different

Working with Branches

  • Feature branch
  • Hotfix branch
  • Bug fixes
  • Whenever you create a local branch, git also creates a reference of the local branch on remote repository
  • Environment Branching strategy
  • GEP is using this methodology
  • Release, DEV, Master, Hotfix
  • Hotfix > Master
  • Feature > DEV
  • Release > QC or UAT
  • Create feature branch from DEV branch
  • Create Hotfix branch from Master branch or depending from which branch the fix has to merge to Master
  • Release branch will be in sync with strict Release schedule
  • Resolving Merge Conflicts

Better team Collaboration

  • FORK
  • Share repo model

--

--