CAT201 03 Intro Git Github
CAT201 03 Intro Git Github
Control with
and
TAN TIEN PING
Reference
John Loeliger and Matthew McCullough (2012). Version control with Git.
O’Reilly Media. California.
https://github.com/ITboy/book/blob/master/Version%20Control%20with%20G
it%2C%202nd%20Edition.pdf
Ref: https://mikemcquaid.com/2014/01/18/why-use-version-control/
Version Control System
A version control system (VCS) is a tool
that manages and tracks a software,
documents, and data.
Track changes: who, what, why and
when.
Manage changes: add, modify, undo,
redo changes, …
Ref: https://mikemcquaid.com/2014/01/18/why-use-version-control/
Version Control System
VCS is very important especially in open-source software development as most developer often
work independently at different modules or issues, and they must submit the update/changes
independently.
There are many VCS available. The most popular is Git.
Git was first introduced by Linus Torvalds to support the development of Linux kernel, but now it
has been expanded to support other software development, other OS (e.g. Windows), and it can
also be used to keep documents and data.
Previous VCS
The Source Code Control System (SCCS) was introduced in 1970s on Unix. The earliest VCS. It
introduced the concept of repository. User must unlock a file and lock it back after update.
The Revision Control System (RCS) was introduced in 1980s on Unix. Introduced the concept of
forward delta and reverse delta concept.
The Concurrent Version System (CVS) was introduced in 1986 on Unix. De facto standard for
open-source development for a long time. CVS allows a file to be independently modified at
private repository and then merged.
BitKeeper was available in 2000. It eliminates central repository and use a distributed one
instead. BitKeeper VCS – commercial system, used for Linux kernel development in 2002. In
2005, BitKeeper ends support for “free use” version1.
Local VCS
e.g. RCS Centralized VCS
e.g. CVS, subversion
Distributed VCS
e.g. git
Ref: https://git-scm.com/book/en/v1/Getting-Started-About-Version-Control
Git
Why Git is introduced? Existing VCS that time does not meet the needs of Linux development.
◦ Allow parallel, independent and simultaneous development in private repositories without constant
synchronization with central repository.
◦ Able to handle large number of developers at a time.
◦ Quick and efficient.
◦ Maintain integrity and thrust. Data is not compromised during transfer, and in the central repository.
◦ Enforce accountability. Keep track of who did what changes.
◦ Immutability or cannot be modified once created.
◦ Atomic transaction. A transaction that is performed or not at all.
◦ Support and encourage branch development and merging.
◦ Complete repositories.
◦ Clean design.
◦ Free & Freedom.
How you can use Git
Sole user
◦ Use it just like a local VCS. Track and manage the changes
that you made on files.
◦ Upload/download project to/from a remote server (e.g.
GitHub).
Ref: https://proandroiddev.com/how-to-set-up-an-efficient-development-workflow-with-git-and-ci-cd-5e8916f6bece
Installing Git
The git installers for different OS is available at https://git-scm.com/downloads . Alternative
installation procedure are available for Linux and MacOs.
Ubuntu
$ sudo apt-get install git
Fedora
$ sudo yum install git
If you are neither familiar with DOS prompt nor Unix Commands, I would suggest you to select “Use Git and Optional
Unix tools from the Commands Prompts”.
There are not many Unix/Linux Commands that you have to learn to use git. These are the commands that we will
use.
◦ pwd : tells you where you are.
◦ ls -a: list all files in the current directory, including hidden files.
◦ cd <directory>: change directory.
You may also want to change the default (text) editor, to Notepad++ or nano, if you are not familiar with vim. vim is a
very powerful editor, but it has a steep learning curve.
Common Version Control Terms
Repository: A collection of files managed with version control.
Branch: A unique copy of the file(s) in the repository with its own history of edits
Commit: Saving the changes you made to the files to your local repository.
Pull: Grab changes that are not in your current repository from another repository.
Push: Send your changes to a shared repository.
HEAD: a reference to the current active commit.
Master branch: primary branch/trunk.
Git Commands
git checkout <branch>
git add <file> Working directory
git reset
Local repository
remote repository
git pull
Local machine Remote server (e.g.
GitHub)
git push
module A{ … }
module C{ … }
module B{ … } module B{ … }
module C{ … }
module B{ … }
module C{ … }
How to create a version of File(s)?
0. Initialize a Git repository
1. Putting the file in the repository
2. Staging a file
3. Commit a file - a version is created
4. Repeat step 2 & 3 if you make changes to file
5. (Optional) pushing the file to a remote repository for sharing or even backup.
How to …
How to retrieve a version of file(s)?
◦ Use “git checkout” command
You can also execute commit and without opening up the text editor using the following command:
$ git commit -m ”my comments"
You can reset the previous commit by typing,
keep the changes in staging area:
$ git reset --soft HEAD~1
Ref: https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting
$ git checkout hotfix $ git checkout hotfix
$ git reset HEAD~2 $ git checkout HEAD~2
Ref: https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting
Viewing Changes
To view the history of all (commit)
changes made, use “git log”:
$ git log
To view the changes made in each commit:
$ git log -p
master master
$ git add .
$ git commit -m “add
HelloUniverse.java”
master
$ git commit
master
$ git checkout head~1 Note, You can move head backward using head~1,
but you cannot move the head forward this way,
but using the commit_hash or branch name.
master
$ git commit
newfeatures
master
newfeatures
Git Merge: Updating your branch
Fast forward merge After branching out, there will be a point
where you want to merge the branch back
master newfeatures to the (normally master) branch.
Affected file.
Open the affected file. You will
notice tags like “<<<<<<“,
“=======“ and “>>>>>>” that
tell you where the content
come from.
download button
Create a GitHub Page
Go to Settings Tab
Thank You!