2. Agenda
What is Git?
What is Repository?
Version Control System.
Centralised Version Control System.
Distributed Version Control system.
Git Workflow.
Git Commands.
Features and Benefits of Git.
3. What is Git??
Git was created by Linus Torvalds in April 2005 to develop Linux Kernel.
Replacement for bitkeeper to manage Linux Kernel changes.
A command line version control program.
Uses checksums to ensure Data Integrity.
Distributed Version Control.
Cross Platform(Including Windows).
Free & open-source control system .
What is Repository?
Repo = Repository
Usually needs to organize a single project.
It contains folders, files, images, videos, spreadsheets and datasets --- anything your project needs.
5. Version Control System
A way to manage files and directories
Track changes over time
Recall previous versions
Source control is a subset of VCS
Version 1
Repository
File 1
File 2
File 3
Version 2
File 1
File 2
File 3
File 2.1
Snapshot
Snapshot
Fig : Version control system
6. Centralised Version Control System
Uses a central server to store files.
Every operation is performed directly on the repository.
All the versions of the file are stored on the central VCS server.
Incase the central server crashes, the entire data of the project will be lost. Hence Distributed VCS was Introduced.
Centralised
VCS server
System A file
System B file
System A file System B file
Fig : Centralised Version Control System
7. Distribution Version Control
No need to connect central server.
It can work without Internet connection.
Developers can Work Independently and merge their work later.
Every copy of a Git repository can serve either as a client or a server.
It can track changes, not Versions.
Repo Repo
Repo
client client
client
Fig : Distributed
client
client
client client
Repo
Fig : Traditional
8. Git Workflow
Working Directory
Modify working Copy
Review Changes
Commit changes
Review Changes
edit, add, move files
Status and diff operation
Commit and push operation
ammend and push operation
Clone operation
Update Operation
Push operation
Push operation
9. Git Workflow is divided into three stages
Working Directory
Staging Area
(Index)
Git Directory
(Repository)
Checkout the changes
Stage files
Commit
10. Git Commands
1. git config - sets the author name and email address respectively to be used with your commits
Usage : git config –global user.name “[name]”
Usage : git config –global user.email “[email address]”
2. git init : used to start a new repository
Usage : git init [git repository]
3. git clone – used to obtain a repository from an existing URL
Usage : git clone [url]
4. git add : adds a file to a staging area
Usage : git add [file]
Usage : git add *
5. git status : this command lists all the files that you have to be committed
Usage : git status
11. 6. git commit
Usage : git commit –m “[type in the commit message]”
This command records or snapshots the file permanently in the version history.
Usage : git commit –a
This command commits anyfiles you hav added with the git add command and also commits any files u have changed since
then.
7. git diff
Usage : git diff
This command shows the differences which are not yet staged.
Usage : git diff –staged
This command shows the differences between the files in the staging area and the latest version present.
8. git reset
Usage : git reset [file]
This command unstages the file, but it preserves the file contents.
Usage : git reset [commit]
This command undo’s all the commits after the specified commit and preserves the changes locally.
Usage : git reset –hard[commit]
This command discards all history and goes back to the specified commit.
12. 9. git rm – deletes the file from your working directory and stages the deletion.
Usage : git rm [file]
10. git log
Usage : git log
This command used to list the version history for the current branch.
Usage : git log –follow[file]
This command lists version history for a file, including renaming files also.
11. git show - This command shows the meta data and content changes of the specified commit.
Usage : git show [commit]
12. git tag – used to give tags to the specified amount
Usage : git tag [commit ID]
13. git merge : merges the specified branch ‘s history into the current branch.
Usage : git merge [branch name]
13. 14. git branch
Usage : git branch
This commands lists all the local branches in the current repository
Usage : git branch [branch name]
This command creates a new branch.
Usage : git branch –d [branch name]
This command deletes the feature branch.
15. git checkout
Usage : git checkout [branch name]
This command is used to switch from one branch to another.
Usage : git checkout –b [branch name]
This command creates a new branch and also switches to it.
16. git remote
Usage : git remote add [variable name] [remote server link]
This command is used to connect your local repository to the remote server.
14. 17. git push
Usage : git push [variable name] [master]
This command sends the committed changes o master branch to your remote repository.
Usage : git push [variable name] [branch]
This commands sends the branch commits to your remote repository.
Usage : git push –all [variable name]
This command pushes all branches to your remote repository.
18. git pull – fetches and merges changes to your remote server to the working directory.
Usage : git pull [repository link]
19. git stash
Usage : git stash save
This command temporarily stores all the modified tracked files.
Usage : git stash list
This command lists all stashed changesets.
Usage : git stash drop
This command discards the most recently stashed changeset.
15. Github remote
server
Forked branch Master
fork
Pull request
Origin/master “branch”
Working Directory
Repo
Stage
add
Commit
merge
checkout
merge
Local
Origin/master
references remote
server branch and
tries to say in sync
Someone else
master
Pull/fetch
push
17. Features of Git
Open source
Scalable
Distributed
Security
Speed
Supports non-linear development
Branching and Merging
Data Assurance
Staging Area
Maintains the clean History
Benefits of Git
Saves time
Offline Working
Undo Mistakes
Track Changes
Free and open Source
Implicit backup
No need of powerful Hardware
Easier Branching