This document provides an introduction to version control systems and Git. It explains what version control is, the advantages it provides, and the different types of version control systems including local, centralized, and distributed. It then describes Git in more detail, covering its architecture, features, basic commands, and how to initialize and connect a local and remote Git repository. The document concludes with instructions for a lab on using basic Git commands.
2. Introduction to Version
Control System (VCS)
– Version Control (aka Revision Control aka Source Control)
is a system that records changes to a file or set of files
over time so that you can recall specific versions later.
– Why do you care? So when you mess up you can easily
get back to a previous working version.
– It is very helpful when multiple users are continuously
working or changing a document.
DevOps course by Abdul Rahim
3. Using VCS, the Users can review the document history to
find out the following details:
– Which changes were made in the document?
– Who made the changes in the document?
– When were the changes made in the document?
– Why were changes needed?
Advantages of Version
Control System
DevOps course by Abdul Rahim
4. Advantages of Version
Control System
A good VCS does the following:
– Backup and Restore.
– Synchronization.
– Short-term undo
– Long-term undo.
– Track Changes.
– Track Ownership.
– Sandboxing, or insurance against yourself.
– Branching and merging
DevOps course by Abdul Rahim
5. Type Of VCS
There are two types of VCS, namely:
– Local Version Control Systems (LVCS).
– Centralized version control system (CVCS).
– Distributed version control system (DVCS).
DevOps course by Abdul Rahim
6. Local Version Control
Systems (LVCS)
– You’ve probably cooked up your own version control system without realizing it
had such a geeky name. Got any files like this?
– Rahim-Resume-Oct2014.docx
– Rahim-Resume-Mar2015.docx
– Rahim-Resume-Mar2015-OLD.docx
– It’s why we use “Save As”. You want the new file without obliterating the old one.
It’s a common problem, and solutions are usually like this:
– Make a single backup copy (Document.old.txt).
– If we’re clever, we add a version number or date: CV_V1.txt or CVMarch2015.txt
– We may even use a shared folder so other people can see and edit files without sending
them over email. Hopefully they relabel the file after they save it.
DevOps course by Abdul Rahim
8. Centralized version
control system (CVCS)
DevOps course by Abdul Rahim
– Centralized version control system works on a Client-Server
relationship. Server will have all the information which is
transferred to the client.
– The main disadvantage of the Centralized VCS is that it is a single
point of failure. If central server went down then you cannot used
it.
1. Concurrent Versions System (CVS).
2. Subversion (SVN).
3. TeamCity.
10. Distributed version
control system (DVCS)
DevOps course by Abdul Rahim
– Distributed version control system has a centralized repository as
well as all developers have local copy of repository.
– Developers can work on their local copy simultaneously. If the
central server went down then also there will be no impact
because of the local repository.
1. Git.
2. Mercurial.
3. Bazaar.
4. Visual Studio Team Services
11. Git Features
– Tracks history
– Free and open source
– Supports non-linear development
– Creates backups
– Scalable
– Supports collaboration
– Branching is easier
– Distributed development
– Secure
DevOps course by Abdul Rahim
13. Lab – Git
DevOps course by Abdul Rahim
1. Install Git
2. Setting up name and e-mail address
3. Add SSH key
4. Creating Github Account
If you already have Git installed and Github account, skip the lab
and help others.
14. Lab 1– Install Git
DevOps course by Abdul Rahim
• https://git-scm.com/download/winWindows
• sudo apt-get install git-all
• https://git-scm.com/download/linuxUbuntu
• brew install git
• https://git-scm.com/download/macMacOS
15. Lab 2– Setting up name
and e-mail address
DevOps course by Abdul Rahim
– If you've never used git before, first you
need to set up your name and e-mail. Open
Git Bash & run the following commands to
let git know your name and e-mail address.
git config --global user.name "Your Name"
git config --global user.email "your_email@whatever.com"
16. Lab 3– Add SSH key
DevOps course by Abdul Rahim
– For pushing changes to Github/cloning a private repo, it needs to authenticate
you, so for every push, you will have to enter your username & password which
can cause problems. So to solve that we can add an SSH key of your PC, so that
Github knows whenever you are trying to clone/push changes, that this PC is
secured and has SSH(secure shell).
– Generate SSH key locally
– ssh-keygen -t rsa -b 4096 -C "your_email@whatever.com"
– eval $(ssh-agent -s)
– ssh-add ~/.ssh/id_rsa
– cat ~/.ssh/id_rsa.pub
17. Lab 3– Add SSH key
DevOps course by Abdul Rahim
– Copy the SSH key and then we need to go to the GitHub account and click on
– Profile -> Settings -> SSH & GPG Keys -> New SSH Key -> Paste.
– This will add an SSH key to your account, to test if it is working enter
– ssh -T git@github.com
18. Lab 4– Creating Github
Account
DevOps course by Abdul Rahim
– Go to https://www.github.com/ and Signup
– your username will be your github address e.g.
https://github.com/rahimkhanabdul
22. GIT Repository
DevOps course by Abdul Rahim
– A repository is the most basic element and a virtual storage
of your project. It allows you to save versions of your code,
which you can access when needed.
– Can be
Private: Only certain people with access can see the repo
Public: Anyone can see the repo
– There is a local repository & a remote repository, you make
changes to local repository and push them to remote.
23. Obtain a GIT Repository
DevOps course by Abdul Rahim
– You typically obtain a Git repository in one of two ways:
1. You can take a local directory that is currently not under
version control, and turn it into a Git repository, or
2. You can clone an existing Git repository from elsewhere.
– In either case, you end up with a Git repository on your
local machine, ready for work.
24. Initializing / Creating a
Local Repository
DevOps course by Abdul Rahim
– If you have a project directory that is currently not under version control and
you want to start controlling it with Git, you first need to go to that project’s
directory.
– Open GIT Bash
cd <project-directory>
– and type:
git init
– This creates a new subdirectory named .git into your <project-
directory> that contains all of your necessary repository files — a
Git repository skeleton.
25. Create a Remote
Repository
DevOps course by Abdul Rahim
– Login to www.github.com
– Click the + at the top right,
– New Repository,
– Enter Repository Name, Description, Chose Public and
initialize with a README.
– Click create repository
– Your Repository will be created with following link
github.com/<username>/<repo-name>
26. Connect Local & Remote
Repository
DevOps course by Abdul Rahim
– Open Git bash and Run the command
git remote add origin https://github.com/<user-name>/<repo-name>.git
– Push the file to the remote repository.
git push origin master
27. Cloning an Existing
Repository
DevOps course by Abdul Rahim
– You can clone a repo, by clicking the code button, and
copying the link. Go to git bash
– Using https
git clone https://github.com/<user-name>/<repo-name>.git
– Using ssh
git clone git@github.com:<user-name>/<repo-name>.git
– Download Zip
28. LAB - GIT Commands
DevOps course by Abdul Rahim
1. Make changes to your project
2. Checking File Differences
3. Commit changes to your local repository
4. Resetting Differences
29. LAB 5- Make changes to
your project
DevOps course by Abdul Rahim
– Create a “hello.html” file in it with the following contents
<h1>Hello, World!<h1>
– Check the current state of the repository.
git status
– Meaning “hello.html” file is added that is currently untracked i.e. it
is not present in git history
30. LAB 6- Checking File
Differences
DevOps course by Abdul Rahim
– Now let’s add the page to staging area of the repository.
git add hello.html or git add .
git status
– It means file is in staging, but it should be committed to
local repo.
31. LAB 6- Checking File
Differences
DevOps course by Abdul Rahim
– Now edit the README.md file, add a bit description like "This is a
test repository" or anything else.
– Check the working directory’s status.
git status
– It shows that new file “hello.html” is yet to be committed, and
“README.md” has been modified but it needs to be staged for
commit first.
32. LAB 6- Checking File
Differences
DevOps course by Abdul Rahim
– Now see the differences that have been made
git diff
– It shows that text with - sign was removed and + sign were
added.
33. LAB 6- Checking File
Differences
DevOps course by Abdul Rahim
– Add “README.md” file to staging. And then check status
git status
– It shows that a new file “hello.html” has added and
“README.md” file modified, but yet to be committed
34. LAB 6- Checking File
Differences
DevOps course by Abdul Rahim
– Check differences in staging area
git diff –staged
– It shows both the differences of README.md as well as
a.txt.
35. LAB 7- Commit changes to
your local repository
DevOps course by Abdul Rahim
– Now we will commit the changes in the local repository
git commit –m ‘first commit’
git status
– It shows that your local branch is ahead of origin/master
by 1 commit that we just did. The working tree is clean
and there are no changes to record.
36. LAB 8- Resetting
Differences
DevOps course by Abdul Rahim
– Now we have two changes in a commit. We want to reset
these differences. There are 3 possible options.
1. MIXED (Default Method)
Remove the commit from local repo, and also remove changes from staging area
2. SOFT
Remove the commit from local repo, but keep the files in staging area
3. HARD
Remove the commit from local repo, and staging area and even change the
local files.
37. Method-1 Mixed
(Default Method)
DevOps course by Abdul Rahim
git reset –mixed HEAD^
– Notice changes have been removed from local repo as well as
staging area. So we will need to add and commit files again.
38. Method-2 Soft
DevOps course by Abdul Rahim
git reset –soft HEAD^
– Notice that files are still in staging area but have been
removed from local repo, now you will just need to
commit them again.
39. Method-3 Hard
DevOps course by Abdul Rahim
git reset –hard HEAD^
– Notice the changes have been removed from local repo, as
well as the working tree i.e. the files are now in initial state
that was before your working.
40. PUSH And PULL
DevOps course by Abdul Rahim
– PUSH
– Transfer commits from your local repository to a
remote repository.
– Share modifications with remote team members.
– Commands
git push origin
41. PUSH And PULL
DevOps course by Abdul Rahim
– PULL
– Download content from a remote repository and
update the local repository
– Get modification from remote team members
– Commands
git pull origin
42. LAB - PUSH And PULL
DevOps course by Abdul Rahim
1. Push to Remote Repository
2. Pull from Remote Repository
43. LAB 1- Push to Remote
Repository
DevOps course by Abdul Rahim
– Let’s create the “hello.html” file in it with the following
contents
<h1>Hello, World!<h1>
– Now add and commit the file
– git add .
– git commit –m ‘first commit’
44. LAB 1- Push to Remote
Repository
DevOps course by Abdul Rahim
– Your current changes are in the local repository to verify
that go to Github and verify that “hello.html” does not
exist. Push changes from local repository using the
command:
– git push origin master
45. LAB 2- Pull from Remote
Repository
DevOps course by Abdul Rahim
– You will create a file on Github and then pull those changes in your
local repository
– Go to your Github repository that you created and create new file.
46. LAB 2- Pull from Remote
Repository
DevOps course by Abdul Rahim
47. LAB 2- Pull from Remote
Repository
DevOps course by Abdul Rahim
– Next you will pull the latest changes from remote to local
repository
48. Github Pages
DevOps course by Abdul Rahim
– GitHub Pages is a static site hosting service that takes HTML, CSS, and
JavaScript files straight from a repository on GitHub, optionally runs the
files through a build process, and publishes a website.
– You can use GitHub Pages to host a website about yourself, your
organization, or your project directly from a GitHub repository.
– You get one site per GitHub account and organization, and unlimited
project sites.
– Does not support server side code such as PHP, Python or Ruby
– GitHub Pages are publicly available on the internet, even if their
repositories are private.
49. ASSIGNMENT
DevOps course by Abdul Rahim
– HOST YOUR RESUME ON GITHUB PAGES
– INSTRUCTIONS
Create your Resume Repository on GitHub
Host it through GitHub Pages
50. Reference
DevOps course by Abdul Rahim
– https://git-scm.com/
– https://www.simplilearn.com/tutorials/git-tutorial/what-is-git
– https://www.atlassian.com/git/tutorials/why-git
– https://www.designveloper.com/blog/git-concepts-architecture/
– https://www.youtube.com/
– https://githowto.com/
– https://pages.github.com/
– https://docs.github.com/en/github/working-with-github-pages