Version_Control_with_GIT_Guide_1730081845
Version_Control_with_GIT_Guide_1730081845
COMMON GIT
04 GIT LIFECYCLE 05 COMMANDS
06 MERGING IN GIT
RESOLVING
07 MERGE
08 GIT WORKFLOW
CONFLICTS
Imagine, Developer A creates a software, and starts a company with this software.
Developer A Software
As the company grows, Developer A hires more people to enhance the features of this
software. Developer A shares the source code copy with each one of them to work on
Vers ion 1
Developer B
Vers ion 1
Vers ion 1
Developer A Vers ion 1 Developer C Software
Developer D
Copyright IntelliPaat, All rights reserved
Problems before Version Control
Vers ion 2
Vers ion 1
Developer B
Vers ion 1
Vers ion 1
Developer C Developer A Software
Developer A, verifies the changes, and if all looks well, simply replaces the code of
the main software
Vers ion 1
Developer B
Vers ion 2
Vers ion 1
Developer C Developer A Software
Now, the problem starts here, Developer C also finished his work, and submits the
changes to Developer A. But, Developer C worked on the code of Version 1.
Vers ion 1
Developer B
Vers ion 2
Vers ion 3
Vers ion 1
Developer C Developer A Software
Developer A verifies the features, takes the code changes and manually integrates
them with Version 2 code
Vers ion 1
Developer B
Vers ion 3
Vers ion 1
Developer C Developer A Software
Similarly when Developer C is done with his work, submits the work to Developer A.
Developer A verifies it, manually integrates the changes with Version 3
Vers ion 1
Developer B
Vers ion 4
Vers ion 1
Developer C Developer A Software
Vers ion 4
Versioning is Automatic
Centralized VCS
Everything except pushing and pulling can Needs a dedicated internet connection
be done without Internet Connection for every operation
Every Developer has full version history on Developers just have the working copy
local hard drive and no version history on their local
drive
Committing and retrieving action is faster
since data is on local drive Committing and retrieving action is
slower since it happens on the internet
Not Good for storing large files which are
binary in nature, this would increase the Good for storing large files, since version
repo size at every commit history is not downloaded
Git is the most popular tool among all the DVCS tools.
Git is a version-control system for tracking changes in computer files and coordinating work on those
files among multiple people. It is primarily used for source-code management in software
development, but it can be used to keep track of changes in any set of files.
Working Staging
Commit
Directory Area
Staging Area In either case, the directory is called the working directory
The project can be tracked by git, by using the command git init
Commit
By doing git init, it automatically creates a hidden .git folder
To add files in the staging area, we use the command git add
Commit
Once the files are selected and are ready in the staging area, they can
now be saved in repository
Working Directory
Staging Area
When we commit a repository in git, the commit is identified by a
commit id
Commit The command for initializing this process is git commit –m “message”
Files committed to
git repository
Files committed to
git repository
Project Folder
HEAD
Project Folder
Master Branch
Project Folder
Master Branch
Master Branch
Commi t ID: Commi t ID:
00001 00002
Feature A Branch
Commi t ID:
00002
Master Branch
Commi t ID: Commi t ID:
00001 00002
Feature A Branch
Commi t ID: Commi t ID:
00002 00004
Master Branch
Commi t ID: Commi t ID: Commi t ID:
00001 00002 00004
Feature A Branch
Commi t ID: Commi t ID:
00002 00004
Making Changes
Syncing Repositories
Parallel Development
Making Changes
Syncing Repositories
Parallel Development
Making Changes
Syncing Repositories
Parallel Development
Making Changes
Syncing Repositories
Parallel Development
Making Changes
Syncing Repositories
Parallel Development
Making Changes
Syncing Repositories
Parallel Development
Making Changes
Syncing Repositories
Parallel Development
Making Changes
Syncing Repositories
Parallel Development
Making Changes
Syncing Repositories
Parallel Development
Syncing Repositories
Parallel Development
Making Changes
Syncing Repositories
Parallel Development
git log
Once you are back and want to retrieve working, type in git stash pop
Making Changes
Syncing Repositories
Parallel Development
Once the developer has finished his code/feature on his branch, the code will have to
be combined with the master branch. This can be done using two ways:
Git Merge
Git Rebase
Feature A
Git Rebase
Master
Git Rebase
Feature A
Git Merge
Git Rebase
Git Merge
Git Rebase
Git Merge But the master moved forward, while the code was being
developed
Master
Test
Git Rebase
Master
Test
Git Merge
Git Rebase
Test
Git Merge
Test
Master Branch
Commi t ID: Commi t ID:
00001 00002
Feature A Branch
Imagine, two developers have been given
the task of adding features to a code,
they both have to add their code in
functions.c file
Feature B Branch
Main()
{
Function1()
{
//Initial Code
}
function.c
Developer A finished his code, and pushes the changes to the master branch
Master Branch
Commi t ID: Commi t ID:
00001 00002
Feature A Branch
Devel oper A
Feature B Branch
Devel oper B
Main() Main()
{ {
Function1() Function1()
{ {
//Initial Code //Initial Code
} }
Function2() Function3()
{ {
//Developer A Code //Developer B Code
} }
} }
function.c function.c
After the Developer A changes his code After the Developer B changes his
and pushes it to master, the code on the code, the code on Feature B branch
Master branch looks something like this looks something like this
Comparing the two code, we can see Feature A Branch is missing Developer A code. Therefore if
we merge Feature A Branch with Master Branch, logically Developer A changes will disappear
Main() Main()
{ {
Function1() Function1()
{ {
//Initial Code //Initial Code
} }
Function2() Function3()
{ {
//Developer A Code //Developer B Code
} }
} }
function.c function.c
Master Branch
Commi t ID: Commi t ID:
00001 00002
Merge Conflict
conflict message
This is the message, you will get when you merge a branch, which has a conflicting file
git mergetool
Hit enter after this prompt, and then you should enter the merge tool
Collaborators
Protecting Branches
Using this feature, you can restrict access on how commits are made to
the branches you specify
Collaborators
Protecting Branches
4. Create a Pull Request from the feature branch to the Master Branch
There are the three popular workflows which are accepted and are followed by various tech companies:
Ma s ter
Ma s ter
Hotfi x
Fea ture
Rel ease
All the changes are directly made on the master, and finally
Centralized Workflow merged on the remote master, once work is finished
GitFlow Workflow
Ma s ter
GitFlow Workflow
Fea ture
Any quick fixes which are required, are done on the Hotfix branch,
Feature Branching
this branch can directly be merged with Master
Hotfi x
v1 v2 v 2.1 v3
Ma s ter
GitFlow Workflow Rel ease
Devel op
Fea ture A
Fea ture B
Copyright IntelliPaat, All rights reserved
Forking in GitHub
D. None of these
D. None of these
A. Master Branch
B. Remote Branch
C. Local Branch
D. None of these
A. Master Branch
B. Remote Branch
C. Local Branch
D. None of these
A. Centralized Workflow
B. Feature Workflow
C. GitFlow Workflow
D. None of these
A. Centralized Workflow
B. Feature Workflow
C. GitFlow Workflow
D. None of these
D. None of these
D. None of these
Thank You
[email protected]