Version Control with Git and GitHub

Hi, I'm Bolaji Ayodeji

Software Engineer and Content Creator who currently works as a Developer Advocate at Commerce Layer.

Learning Objectives

 

  • What is Version Control
  • CVCS vs DVCS
  • What is Git
  • Version Control with Git (Practical)
  • What is GitHub
  • Setting up GitHub (Practical)
  • Git and GitHub are not the same
  • What next?

What is Version Control?

Version Control is:

 

This is the process of tracking and managing changes to software code or a set of files over time.

A version control software keeps track of every modification to the code in a special kind of database.

 

If a mistake is made, developers can restore and compare earlier versions of the code to help fix the mistake while minimizing disruption to all team members or contributors.

CentralIzed VCS

Distributed VCS

Type of VCS

Benefits of Version Control

  • Code backups

  • Preserves efficiency and agility

  • Source code management

  • Traceability

  • Branching and merging

  • Reverting changes

  • Effective collaboration

Version control is an essential part of everyday modern-day software engineering practices and is the core backbone of open-source.

What is Git?

Git is the most widely used modern version control system in the world today. It is a distributed and actively maintained open source project originally developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel.

Git is a Free and Open Sourced Distributed Version Control System

Unlike older centralized version control systems such as SVN and CVS, Git is distributed: every developer has the full history of their code repository locally. Git also works well on a wide range of operating systems and IDEs (Integrated Development Environments).

Version control with Git

//macOS

brew install git

//Linux

sudo apt install git-all

//Windows
choco install git
git init
// Creates or initializes a new git repository

git add index.js or git add * or git add --all
// Proposes this new change and adds it to the index

git remote add origin https://github.com/<GitHub username>/<repo name>.git
// Adds the remote copy to origin repository

git push -u origin main
// Set origin as the upstream remote in your git config (branch main)

git status
// Check what has been going on in git, see whats staged or not.

git commit -m "commit description"
// Tell us what you did and add to HEAD

git push origin main
// Push HEAD to the remote repository

git log
// See the repository history

git pull
// Grabs the latest directory with updates from the remote repository

git clone <url>
// Clone a remote repository to local

Branching

git branch staging
// Creates a new branch named 'staging'

git checkout -b <branch name>
// creates a new branch named <branch name> and switches to it

git checkout main
// switch back to the master branch

git branch -d <branch name>
// deletes the branch named <branch name>

git push origin <branch name>
// push your branch to remote repository

git merge <branch name>
// merge <branch name> into main

What is GitHub?

 

GitHub is a web-based hosting service for version control using Git that is mostly used for software code.

It offers all of the distributed version control and source code management functionality of Git as well as adding its own features.

GitHub Features

  • Repository
  • Commits
  • Tags
  • Pull Request
  • Branch
  • Code editor
  • Codespaces
  • Issues
  • Pull requests
  • Discussions
  • Releases
  • Projects
  • Organizations/ Teams
  • ...

GitLab
BitBucket
Cloudforge

Working with Git and GitHub

 

Create and setup your GitHub account

git config --global user.name "Your username here"

git config --global user.email "your email here"

git config --global color.ui true

git config --global core.editor emacs

git config --list

Differences between Git and GitHub

 

Git is a version control system, a tool to manage your source code history.

 

GitHub is a hosting service for Git repositories.

 

So they are not the same thing;

Git is the tool, GitHub is the service for projects that use Git.

What next?

Once accustomed to the tremendous benefits of version control systems, many developers wouldn't consider working without it, even for non-software projects.

Get the GitHub Student Developer Pack which gives you access to the best developer tools and courses for FREE

Useful resources to learn Git and GitHub

@iambolajiayo

@bolajiayodeji

 

 

bolajiayodeji.com

Made with Slides.com