The document provides information on version control systems and Git concepts like distributed version control, forking and cloning repositories, adding collaborators, branching and merging in Git. It includes step-by-step instructions for setting up a Git demo to showcase creating a repository, adding and committing files, connecting to a remote repository on GitHub, forking a project and cloning it locally, creating and switching branches, adding a collaborator, pulling changes, and merging branches.
2. Whatâs in it for you?
Version Control System
What is Git?
Git Architecture
Git vs GitHub
Fork and Clone
Collaborators
Commands in Git
Git Demo
Branch, Merge and Rebase
Distributed Version Control System
3. Whatâs in it for you?
Whatâs in it for you?Version Control SystemVersion Control System
4. Version Control System (VCS)
System A
File 2.1File 1.1
Repository
Version 2File 1 File 2
System A
Now we make some changes to the files in System A
File 1 ------> saved as File 1.1
File 2 ------> saved as File 2.1
The new files are stored as Version 2 in the repository
VCS allows you to store multiple versions of a system
file in the remote repository
File 1 File 2
Version 1
All the files in System A are stored as Version 1 in the
remote repository
5. Whatâs in it for you?
Whatâs in it for you?Version Control SystemDistributed Version Control
System
6. Distributed Version Control System
Distributed VCS
Developer A
Developer B Developer C
Version 1
Version 2
Version 3
Version 1
Version 2
Version 3
Version 1
Version 2
Version 3Version 1
Version 2
Version 3
All the developers have the entire copy of code on
their local system
7. Distributed Version Control System
Distributed VCS
Developer A
Developer B Developer C
Version 1
Version 2
Version 3
Version 1
Version 2
Version 3
Version 1
Version 2
Version 3Version 1
Version 2
Version 3
Distributed VCS moves from client-server
approach of Central VCS to peer-to-peer
approach
8. Distributed Version Control System
Distributed VCS
Developer A
Developer B Developer C
Version 1
Version 2
Version 3
Version 1
Version 2
Version 3
Version 1
Version 2
Version 3Version 1
Version 2
Version 3
They can update their local repositories with new data
and push it to the central server
9. Distributed Version Control System
Distributed VCS
Developer A
Developer B Developer C
Version 1
Version 2
Version 3
Version 1
Version 2
Version 3
Version 1
Version 2
Version 3Version 1
Version 2
Version 3
Git tool is an example of Distributed VCS
10. Distributed Version Control System
Remote Repository
Commit
Update
Push
Pull
Commit
Update
Push
Pull
Push Pull
Commit Update
Working
Copy
Local
Repository
Working
Copy
Local
Repository
Working
Copy
Local
Repository
11. Whatâs in it for you?
Whatâs in it for you?Version Control SystemWhat is Git?
12. What is Git?
GitHub Remote
Server
Developer 1 Developer 3
Developer 2 Git is used to track changes in the source code
Git is a distributed version control tool used for source code management
Allows multiple developers to work together
Supports non-linear development because
of thousands of parallel branches
Has the ability to handle large projects efficiently
13. Whatâs in it for you?
Whatâs in it for you?Version Control SystemGit vs GitHub
14. Git vs GitHub
2
3
4
It is installed on the local system
It is used to manage different versions of the
source code
It provides a command line to interact with the
files
1
2
3
4
GitHub is a service
It is hosted on the web
It is used to have a copy of the local
repository code
It provides a graphical interface to store
the files
1 Git is a software tool
15. Whatâs in it for you?
Whatâs in it for you?Version Control SystemGit Architecture
18. Git Architecture
Working Directory Local RepositoryStaging Area
git add
git commit
Local
After making all the changes, you commit those
files to the local repository
19. Git Architecture
Working Directory Local RepositoryStaging Area Remote Repository
git add
git commit
git push
Local Remote
You can push the committed files to the remote
repository
20. Git Architecture
Working Directory Local RepositoryStaging Area Remote Repository
git add
git commit
git push
git pull
Local Remote
git pull fetches all the changes from a remote
repository to a local repository
21. Git Architecture
Working Directory Local RepositoryStaging Area Remote Repository
git add
git commit
git push
git pull
git checkout
Local Remote
You can create new branches and switch to
them as and when required
22. Git Architecture
Working Directory Local RepositoryStaging Area Remote Repository
git add
git commit
git push
git pull
git checkout
git merge
Local Remote
After you are done with the changes, you can merge
the new branches to the master branch
23. Whatâs in it for you?
Whatâs in it for you?Version Control SystemGit Concepts
24. Forked
Test_Repository
Fork and Clone
Git Rebase
Pull from a remote
Now that we have
understood Git and itâs
architecture, letâs learn
some git concepts
Git Concepts
Adding Collaborators
Branch in Git
25. Whatâs in it for you?
Whatâs in it for you?Version Control SystemFork and Clone
26. Fork and Clone
Hey, I want to propose
some changes to your
project
Sure. Go ahead and
Fork it
27. Fork and Clone
Git allows you to fork an open source repository. When you fork a repository, you create a copy of it on your
GitHub account.
Someone elseâs
repository
Your own repository
Forked
Test_Repository
Test_Repository
Fork
28. Fork and Clone
After you fork a repository, you can clone it and have a copy of it on your local system.
Someone elseâs
repository
Your own repository
Forked
Test_Repository
Test_Repository
Fork
Local Repository
Clone to you local
computer from GitHub
29. Whatâs in it for you?
Whatâs in it for you?Version Control SystemCollaborators
30. Collaborators
Ok, let me add you as a
Collaborator on GitHub
and give you the
permission
Hey, there are some
errors in your code
repository, I need to fix it
31. Collaborators
GitHub allows you to work with users from all over the world at any given time
Collaborators are GitHub users who are given permission to edit a repository owned by someone else
Anonymous UserRepositoryâs Owner
Your repository
ï± Access all the files
ï± View the files
ï± Make changes to the files
ï± Commit the files
32. Whatâs in it for you?
Whatâs in it for you?Version Control SystemBranch in Git
33. Branch in Git
Suppose you are working on an
application and you want to
add a new feature to the app
You can create a new branch and build the new
feature on that branch
Master branch
New branch
New Feature
Application
ï± By default, you always work on the master branch
ï± The circles on the branch represent various commits made on
the branch
34. Branch in Git
ï± The diagram shows there are 2 new branches
ï± You can develop the features you want separately
Branch in Git is used to keep your changes until they are ready
Master Branch
New Branch
New Branch
Application
35. Branch in Git
ï± The diagram shows there are 2 new branches
ï± You can develop the features you want separately
Branch in Git is used to keep your changes until they are ready
ï± After you develop them completely, you can merge
the newly created branches to the master branch
New Branch
New Branch
Master Branch
Application
36. Whatâs in it for you?
Whatâs in it for you?Version Control SystemGit Merge
37. Git Merge
a b c
d e f
g
Master
Feature
Master
The base commit of
feature branch is b
There can be multiple
divergent branches
38. Git Merge
a b c
d e f
g
Master
Feature
Master
The base commit of
feature branch is b
There can be multiple
commits for each new
branch you create
39. Whatâs in it for you?
Whatâs in it for you?Version Control SystemGit Rebase
40. Git Rebase
a b c
d e f
Master
Feature
f_e_
Feature Feature
d_
Feature
The base commit of feature
branch is changed from b to c
(tip of master)
There is no extra
commit history
41. Git Rebase
a b c
d e f
Master
Feature
f_e_
Feature Feature
d_
Feature
The base commit of feature
branch is changed from b to c (tip
of master)
Resulting history is linear
with no divergent branches
42. Git Rebase
Git Rebase is the process of combining a sequence of commits to a new base commit
ï± The primary reason for rebasing is to maintain a linear project
history
Master
Feature
43. Git Rebase
Git Rebase is the process of combining a sequence of commits to a new base commit
ï± The primary reason for rebasing is to maintain a linear project
history
ï± When you rebase, you âunplugâ a branch and âreplugâ it on
the tip of another branch (usually master)
Master
FeatureFeature
44. Git Rebase
Git Rebase is the process of combining a sequence of commits to a new base commit
ï± The primary reason for rebasing is to maintain a linear project
history
ï± When you rebase, you âunplugâ a branch and âreplugâ it on
the tip of another branch (usually master)
ï± The goal of rebasing is to take all the commits from a feature
branch and put it on the master branch
Master
FeatureFeature
45. Whatâs in it for you?
Whatâs in it for you?Version Control SystemPull from Remote
46. Pull from a Remote
Suppose these 2 developers are working
together on an application
47. Pull from a Remote
They makes changes to their codes and submit
it to the remote repository
Remote
Repository
48. Pull from a Remote
Both of them want to stay updated with the
recent changes to the repository
Remote
Repository
49. Pull from a Remote
They can pull the changes from the remote
repository on to their local system
Remote
Repository
Pull from Remote
Repository
Pull from Remote
Repository
50. Pull from a Remote
Your forked
Repository
Remote
Repository
Local Repository
Pull
Your fork
Repository
ï± Use the following command to check if there
has been any change
$ git pull <RemoteName> <BranchName>
ï± If there is no change, it will notify âAlready up-
to-dateâ. If there is an change, it will merge
those changes to your local repository
You can pull in any changes that have been made from your forked remote repository
to the local repository
51. Whatâs in it for you?
Whatâs in it for you?Version Control SystemCommands in Git
52. Popular Git Commands
git init
Initialize a local Git Repository
git add / git add .
Add one or more files to staging area
git commit âm âcommit messageâ
Commit changes to head but not to the remote
repository
git status
Check the status of your current repository and list
the files you have changed
git log
Provides a list of all the commits made on your
branch
53. Popular Git Commands
git diff
View the changes you have made to the file
git push origin <branch name>
Push the branch to the remote repository so that others
can use it
Git config âglobal user.name âRogerâ
Tell Git who you are by configuring the author name
Git config âglobal user.email roger.1@gmail.com
Tell Git who you are by configuring the author
email id
git clone
Creates a Git repository copy from a remote source
54. Popular Git Commands
git remote add origin <server>
Connect your local repository to the remote server
and add the server to be able to push to it
git branch <branch name>
Create a new branch
git checkout <branch name>
Switch from one branch to another
git merge <branch name>
Merge a branch into the active branch
git rebase
Reapply commits on top of another base tip
55. Whatâs in it for you?
Whatâs in it for you?Version Control SystemDemo on Git
56. Demo on Git
1. Create a Repository
Create a âhello-worldâ folder
Move to hello-world folder
Create a new Git instance for a project
57. Demo on Git
1. Create a Repository
Create a file called readme.txt in the hello-world folder
Check the status of the repository to find out if there have been changes
58. Demo on Git
2. Create a new file, add something to that file and commit those changes to Git
Add the file you just created to the files you would like to commit to change
Commit those changes to the repositoryâs history
59. Demo on Git
2. Create a new file, add something to that file and commit those changes to Git
Add another line to readme.txt and save
View the difference between the file now and how it was at your last commit
60. Demo on Git
3. Create a GitHub account, add username to your Git configuration
Sign up to GitHub account by visiting github.com
Add your GitHub username to your Git Configuration
61. Demo on Git
4. Connect your local and remote repositories and push changes
Github.com Log in
Click the + sign in the top
right
Create a Remote repository
62. Demo on Git
4. Connect your local and remote repositories and push changes
Connect your local to your Remote
Push your file to remote
63. Demo on Git
5. Fork a project from github.com and clone it locally
Github.com/jlord/patchwork
Click the fork button at
the top right
Once the fork is complete, you will get a copy on your account. Copy your forkâs HTTP URL on the right sidebar
Someone elseâs
repository
Your own repository
Forked
Test_Repository
Test_Repository
Fork
Fork Patchwork Repository: Weâll be using github.com/jlord/patchwork
64. Demo on Git
5. Fork a project from github.com and clone it locally
Change the directory
Clone the repository onto your computer
65. Demo on Git
5. Fork a project from github.com and clone it locally
Now, you have got a copy of the repository on your local
computer which is automatically connected to the remote
repository
Go into the folder for the fork it created
If the original repository you forked from has some changes, youâd want to pull those changes as well. So, you need to add another
remote connection to the original repository with its URL
Someone elseâs
repository
Your own repository
Forked
Test_Repository
Test_Repository
Fork
Local
Repository
Clone to you local
computer from
GitHubTest_Repository
66. Demo on Git
5. Fork a project from github.com and clone it locally
67. Demo on Git
6. Create a new branch on your fork for your contribution
Name of the branch is:
add-Simplilearn
Master Branch
add-Simplilearn
Create a new branch
68. Demo on Git
6. Create a new branch on your fork for your contribution
Checkout your branch and go onto a new branch
Push your update to your fork on GitHub
69. Demo on Git
7. Add a collaborator to your project
Visit the repositoryâs GitHub
page
Click settings icon on
the right side menu
Select the collaborators
tab
Type the username and
click add
Add âreporobotâ as a collaborator to your forked Patchwork repositoryâs page
70. Demo on Git
8. Keep your file up to date by pulling in changes from collaborators
It will give a message âAlready up to dateâ, if nothing has changed. If there are changes, it will merge those changes into your
local version.
Check if Reporobot has made any changes to your branch
71. Demo on Git
9. Create a new branch, make changes and merge it to the master branch
Create a new local repository called test
Move to the test folder
Create a new git instance
72. Demo on Git
9. Create a new branch, make changes and merge it to the master branch
Create 2 text files âtest1â and âtest2â in the test repository
Add the two files to master branch and make a commit
73. Demo on Git
9. Create a new branch, make changes and merge it to the master branch
Create a new branch âtest_branchâ
Create a new text file âtest3â
74. Demo on Git
9. Create a new branch, make changes and merge it to the master branch
Add test3 file to the new branch
Move from the master branch to test_branch
75. Demo on Git
9. Create a new branch, make changes and merge it to the master branch
Merge test_branch file to master branch
The master branch has all the files now
76. Demo on Git
9. Create a new branch, make changes and merge it to the master branch
Move from the master branch to test_branch
Modify test3 file and commit the changes
77. Demo on Git
9. Create a new branch, make changes and merge it to the master branch
Check the test3 file in master branch
The file has not been modified in the
master branch
Check the file in test_branch
Switch to the master branch
78. Demo on Git
10. Rebase the newly created files on to master branch
Create 2 new text files test4 and test5
Switch to test_branch
79. Demo on Git
10. Rebase the newly created files on to master branch
Add the files to test branch
Commit the files for rebasing
80. Demo on Git
10. Rebase the newly created files on to master branch
List the files in test_branch
Switch to the master branch
81. Demo on Git
10. Rebase the newly created files on to master branch
List the files in the master branch
Switch to test_branch
Rebase master branch
82. Demo on Git
10. Rebase the newly created files on to master branch
Rebase master branch
Switch to master branch
83. Demo on Git
10. Rebase the newly created files on to master branch
Rebase test_branch
List the files in master branch